Skip to content

Commit

Permalink
Make gcc happy about dangling pointer
Browse files Browse the repository at this point in the history
GCC is emitting a warning about a possible danling pointer on table
like definitions:

warning: possibly dangling reference to a temporary [-Wdangling-reference]
  660 |         auto const& table = get_current_events_table(state_indexes{});
      |                     ^~~~~

Which I think that really comes from the use of state_indexes{} as
argument:

  note: the temporary was destroyed at the end of the full expression
  660 |         auto const& table = get_current_events_table(state_indexes{});
      |                             ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~

Clang is quiet about this and make me think that is a false positive
since the metaprogramming code is using just the type of the state_indexes
as much as I can see.

Signed-off-by: Jose Luis Rivero <[email protected]>
  • Loading branch information
j-rivero committed Apr 17, 2024
1 parent 0cc079d commit 9455498
Showing 1 changed file with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,8 @@ class state_transition_table {
void
check_default_transition()
{
auto const& ttable = transition_table<none>( state_indexes{} );
auto st = state_indexes{};
auto const& ttable = transition_table<none>( st );
ttable[current_state()](*this, none{});
}

Expand All @@ -544,15 +545,17 @@ class state_transition_table {
void
exit(Event&& event)
{
auto const& table = exit_table<Event>( state_indexes{} );
auto st = state_indexes{};
auto const& table = exit_table<Event>( st );
table[current_state()](states_, ::std::forward<Event>(event), *fsm_);
}

template < typename Event >
actions::event_process_result
process_transition_event(Event&& event)
{
auto const& inv_table = transition_table<Event>( state_indexes{} );
auto st = state_indexes{};
auto const& inv_table = transition_table<Event>( st );
return inv_table[current_state()](*this, ::std::forward<Event>(event));
}

Expand Down Expand Up @@ -655,10 +658,11 @@ class state_transition_table {
event_set
current_handled_events() const
{
auto const& table = get_current_events_table(state_indexes{});
auto st = state_indexes{};
auto const& table = get_current_events_table(st);
auto res = table[current_state_](states_);
auto const& available_transitions
= get_available_transitions_table(state_indexes{});
= get_available_transitions_table(st);
auto const& trans = available_transitions[current_state_];
res.insert( trans.begin(), trans.end());
return res;
Expand All @@ -667,7 +671,8 @@ class state_transition_table {
event_set
current_deferrable_events() const
{
auto const& table = get_current_deferred_events_table(state_indexes{});
auto st = state_indexes{};
auto const& table = get_current_deferred_events_table(st);
return table[current_state_](states_);
}

Expand Down

0 comments on commit 9455498

Please sign in to comment.