Skip to content

Commit

Permalink
Fix GCC/CMake warnings for Noble (gazebosim#2375)
Browse files Browse the repository at this point in the history
* Use latest 1.14 google-test in gtest_setup

Signed-off-by: Jose Luis Rivero <jrivero@osrfoundation.org>

* Make gcc happy about dangling pointer

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 <jrivero@osrfoundation.org>
Co-authored-by: Alejandro Hernández Cordero <ahcorde@gmail.com>
  • Loading branch information
j-rivero and ahcorde authored Apr 29, 2024
1 parent 0b54328 commit 3444847
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
9 changes: 5 additions & 4 deletions examples/plugin/custom_sensor_system/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ add_subdirectory(${sensors_clone_SOURCE_DIR}/examples/custom_sensor ${sensors_cl

add_library(${PROJECT_NAME} SHARED ${PROJECT_NAME}.cc)
target_link_libraries(${PROJECT_NAME}
PRIVATE gz-plugin${GZ_PLUGIN_VER}::gz-plugin${GZ_PLUGIN_VER}
PRIVATE gz-sim${GZ_SIM_VER}::gz-sim${GZ_SIM_VER}
PRIVATE gz-sensors${GZ_SENSORS_VER}::gz-sensors${GZ_SENSORS_VER}
PRIVATE odometer
PRIVATE
gz-plugin${GZ_PLUGIN_VER}::gz-plugin${GZ_PLUGIN_VER}
gz-sim${GZ_SIM_VER}::gz-sim${GZ_SIM_VER}
gz-sensors${GZ_SENSORS_VER}::gz-sensors${GZ_SENSORS_VER}
odometer
)
target_include_directories(${PROJECT_NAME}
PUBLIC ${sensors_clone_SOURCE_DIR}/examples/custom_sensor)
3 changes: 2 additions & 1 deletion examples/standalone/gtest_setup/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ set(GZ_SIM_VER ${gz-sim8_VERSION_MAJOR})
include(FetchContent)
FetchContent_Declare(
googletest
URL https://github.com/google/googletest/archive/609281088cfefc76f9d0ce82e1ff6c30cc3591e5.zip
# Version 1.14. Use commit hash to prevent tag relocation
URL https://github.com/google/googletest/archive/f8d7d77c06936315286eb55f8de22cd23c188571.zip
)
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)
Expand Down
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 3444847

Please sign in to comment.