boost-ext / sml

C++14 State Machine library
https://boost-ext.github.io/sml
Boost Software License 1.0
1.1k stars 173 forks source link

Negating a guard does not compile on MSVC latest with C++20 #515

Open Asaaj opened 1 year ago

Asaaj commented 1 year ago

Expected Behavior

Using the event<e>[ !guard ] notation should compile on all platforms.

Actual Behavior

The above notation does not compile on MSVC version 19.33 with C++20 enabled. Note that it does compile in 19.33 with C++17, and in 19.32 with C++17/20

Error from example linked below:

<source>(31): error C2676: binary '[': 'boost::ext::sml::v1_1_6::front::event<e2>' does not define this operator or a conversion to a type acceptable to the predefined operator
https://raw.githubusercontent.com/boost-ext/sml/master/include/boost/sml.hpp(2148): note: could be 'auto boost::ext::sml::v1_1_6::front::event<e2>::operator [](const T &) const'
<source>(31): error C2783: 'auto boost::ext::sml::v1_1_6::front::event<e2>::operator [](const T &) const': could not deduce template argument for '__formal'
https://raw.githubusercontent.com/boost-ext/sml/master/include/boost/sml.hpp(2148): note: see declaration of 'boost::ext::sml::v1_1_6::front::event<e2>::operator []'
Compiler returned: 2

Steps to Reproduce the Problem

  1. Implement example using the [! guard] notation, such as the "Action Guards" example in the official examples.
  2. Compile with MSVC 19.33 using /std:c++20
  3. Fails to compile

A simplified version of that example demonstrating this issue is available here: https://godbolt.org/z/58necxe5a

Specifications

krzysztof-jusiak commented 1 year ago

hmm, don't fully understand why the operator can't be deduced; defo seems like msvc bug; will keep trying to find some local solution and will report the issue to the Microsoft; thanks for pointing it out @Asaaj

eido79 commented 1 year ago

As a workaround, change the capture list of the lambda function to &. This makes the compiler accept the code, and shouldn't make any difference in the generated code, as you're not using any captured variable.

https://godbolt.org/z/dG4Yb4jMK

krzysztof-jusiak commented 1 year ago

Nicez thanks @, BTW msvc is aware of the issue and working on the fix.