boost-ext / sml

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

gcc 10.5 warning: array subscript is outside array bounds #614

Closed cmigliorini closed 6 months ago

cmigliorini commented 6 months ago

Hello, I can't seem to reproduce the following issue with a simple template (yet), but I thought perhaps someone else have encountered this so I'd create this ticket anyway.

Expected Behavior

SML compiles without warning

Actual Behavior

gcc 10.5.0.1 issues warnings such as

sml-1.1.9/include/boost/sml.hpp:553:13: 
  warning: array subscript 0 is outside array bounds of 
  'boost::ext::sml::v1_1_9::aux::zero_wrapper<MyDep::operator()() const::<lambda(MyDep&)>, void> [1]'
   [-Warray-bounds]
sml-1.1.9/include/boost/sml.hpp:336:22: warning: array subscript 48 is outside array bounds of 'boost::ext::sml::v1_1_9::front::seq_<boost::ext::sml::v1_1_9::aux::zero_wrapper<boost::ext::sml::v1_1_9::front::seq_<boost::ext::sml::v1_1_9::aux::zero_wrapper<boost::ext::sml::v1_1_9::front::seq_<boost::ext::sml::v1_1_9::aux::zero_wrapper<boost::ext::sml::v1_1_9::front::seq_<boost::ext::sml::v1_1_9::aux::zero_wrapper<boost::ext::sml::v1_1_9::front::seq_<boost::ext::sml::v1_1_9::aux::zero_wrapper<boost::ext::sml::v1_1_9::aux::zero_wrapper<void (MyOtherDep::*)(const MyEvent&), 
 void (MyOtherDep::*)(const MyEvent&)>, void>,
 boost::ext::sml::v1_1_9::aux::zero_wrapper<MyOtherDep::operator()() const::<lambda(MyOtherDep&)>, void> >, void>,
 boost::ext::sml::v1_1_9::aux::zero_wrapper<MyOtherDep::operator()() const::<lambda(MyOtherDep&)>, void> >, void>,
 boost::ext::sml::v1_1_9::aux::zero_wrapper<MyOtherDep::operator()() const::<lambda(MyOtherDep&)>, void> >, void>,
 boost::ext::sml::v1_1_9::aux::zero_wrapper<MyOtherDep::operator()() const::<lambda(MyOtherDep&)>, void> >, void>,
 boost::ext::sml::v1_1_9::aux::zero_wrapper<MyOtherDep::operator()() const::<lambda(MyOtherDep&)>, void> > [1]' [-Warray-bounds]

Steps to Reproduce the Problem

Unfortunately I was not able (yet) to recreate the problem outside of our private code.

Specifications

krzysztof-jusiak commented 6 months ago

not sure exactly, but it's likely the zero_wrapper (for zero sized guards/ctions without capture). Can you try with -DBOOST_SML_CFG_DISABLE_MIN_SIZE? Thanks.

cmigliorini commented 6 months ago

That solved the problem, thanks! Should we just keep this now?

krzysztof-jusiak commented 6 months ago

Great, thanks for sharing. This warning is a false positive in gcc 10.5 as there is no array indexing actually happening; the only reason this wknd is there is to have zero sized guards/actions if lambda without capture (which in C++ still needs sizeof 1), so there is an array wknd used to get it to zero were possible. So, as I see it you have a few options

So it depends on the trade-offs you are considering.

cmigliorini commented 6 months ago

Thank you! I would have added the #pragma if no answer came :), so now I can add it knowing it's truly a false positive -- btw this false positive from gcc also affect many code around, as I could see before I submitted this.