Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gcc 13.1 -Wdangling-reference warnings #1944

Closed
AaronVanGeffen opened this issue May 15, 2023 · 6 comments
Closed

gcc 13.1 -Wdangling-reference warnings #1944

AaronVanGeffen opened this issue May 15, 2023 · 6 comments
Labels

Comments

@AaronVanGeffen
Copy link
Member

Getting a few more warnings on my end when compiling with gcc 13.1. I have disabled -Werror, so I can work around them, but we should look into these:

[95/190] Building CXX object src/OpenLoco/CMakeFiles/OpenLoco.dir/src/Vehicles/Routing.cpp.o
/home/aaron/Repositories/OpenLoco/OpenLoco/src/OpenLoco/src/Vehicles/Routing.cpp: In function ‘void OpenLoco::Vehicles::findAllUsableTrackPieces(const LocationOfInterest&, FilterFunction, LocationOfInterestHashMap&)’:
/home/aaron/Repositories/OpenLoco/OpenLoco/src/OpenLoco/src/Vehicles/Routing.cpp:554:29: warning: possibly dangling reference to a temporary [-Wdangling-reference]
  554 |                 const auto& targetPiece = World::TrackData::getTrackPiece(elTrack->trackId())[elTrack->sequenceIndex()];
      |                             ^~~~~~~~~~~
/home/aaron/Repositories/OpenLoco/OpenLoco/src/OpenLoco/src/Vehicles/Routing.cpp:554:119: note: the temporary was destroyed at the end of the full expression ‘OpenLoco::World::TrackData::getTrackPiece(((size_t)elTrack->OpenLoco::World::TrackElement::trackId())).nonstd::span_lite::span<const OpenLoco::World::TrackData::PreviewTrack>::operator[](((nonstd::span_lite::span<const OpenLoco::World::TrackData::PreviewTrack>::size_type)elTrack->OpenLoco::World::TrackElement::sequenceIndex()))’
  554 |                 const auto& targetPiece = World::TrackData::getTrackPiece(elTrack->trackId())[elTrack->sequenceIndex()];
      |                                                                                                                       ^
At global scope:
cc1plus: note: unrecognized command-line option ‘-Wno-unused-private-field’ may have been intended to silence earlier diagnostics
[115/190] Building CXX object src/OpenLoco/CMakeFiles/OpenLoco.dir/src/Windows/Construction/Common.cpp.o
/home/aaron/Repositories/OpenLoco/OpenLoco/src/OpenLoco/src/Windows/Construction/Common.cpp: In function ‘void OpenLoco::Ui::Windows::Construction::Common::setNextAndPreviousTrackTile(const OpenLoco::World::TrackElement&, const OpenLoco::World::Pos2&)’:
/home/aaron/Repositories/OpenLoco/OpenLoco/src/OpenLoco/src/Windows/Construction/Common.cpp:631:25: warning: possibly dangling reference to a temporary [-Wdangling-reference]
  631 |             const auto& piece = TrackData::getTrackPiece(elTrack.trackId())[elTrack.sequenceIndex()];
      |                         ^~~~~
/home/aaron/Repositories/OpenLoco/OpenLoco/src/OpenLoco/src/Windows/Construction/Common.cpp:631:100: note: the temporary was destroyed at the end of the full expression ‘OpenLoco::World::TrackData::getTrackPiece(((size_t)(& elTrack)->OpenLoco::World::TrackElement::trackId())).nonstd::span_lite::span<const OpenLoco::World::TrackData::PreviewTrack>::operator[](((nonstd::span_lite::span<const OpenLoco::World::TrackData::PreviewTrack>::size_type)(& elTrack)->OpenLoco::World::TrackElement::sequenceIndex()))’
  631 |             const auto& piece = TrackData::getTrackPiece(elTrack.trackId())[elTrack.sequenceIndex()];
      |                                                                                                    ^
/home/aaron/Repositories/OpenLoco/OpenLoco/src/OpenLoco/src/Windows/Construction/Common.cpp: In function ‘void OpenLoco::Ui::Windows::Construction::Common::setNextAndPreviousRoadTile(const OpenLoco::World::RoadElement&, const OpenLoco::World::Pos2&)’:
/home/aaron/Repositories/OpenLoco/OpenLoco/src/OpenLoco/src/Windows/Construction/Common.cpp:655:25: warning: possibly dangling reference to a temporary [-Wdangling-reference]
  655 |             const auto& piece = TrackData::getRoadPiece(elRoad.roadId())[elRoad.sequenceIndex()];
      |                         ^~~~~
/home/aaron/Repositories/OpenLoco/OpenLoco/src/OpenLoco/src/Windows/Construction/Common.cpp:655:96: note: the temporary was destroyed at the end of the full expression ‘OpenLoco::World::TrackData::getRoadPiece(((size_t)(& elRoad)->OpenLoco::World::RoadElement::roadId())).nonstd::span_lite::span<const OpenLoco::World::TrackData::PreviewTrack>::operator[](((nonstd::span_lite::span<const OpenLoco::World::TrackData::PreviewTrack>::size_type)(& elRoad)->OpenLoco::World::RoadElement::sequenceIndex()))’
  655 |             const auto& piece = TrackData::getRoadPiece(elRoad.roadId())[elRoad.sequenceIndex()];
      |                                                                                                ^
At global scope:
cc1plus: note: unrecognized command-line option ‘-Wno-unused-private-field’ may have been intended to silence earlier diagnostics
[140/190] Building CXX object src/OpenLoco/CMakeFiles/OpenLoco.dir/src/Windows/Options.cpp.o
/home/aaron/Repositories/OpenLoco/OpenLoco/src/OpenLoco/src/Windows/Options.cpp: In function ‘void OpenLoco::Ui::Windows::Options::Regional::prepareDraw(OpenLoco::Ui::Window&)’:
/home/aaron/Repositories/OpenLoco/OpenLoco/src/OpenLoco/src/Windows/Options.cpp:1351:19: warning: possibly dangling reference to a temporary [-Wdangling-reference]
 1351 |             auto& language = Localisation::getDescriptorForLanguage(Config::get().language);
      |                   ^~~~~~~~
/home/aaron/Repositories/OpenLoco/OpenLoco/src/OpenLoco/src/Windows/Options.cpp:1351:68: note: the temporary was destroyed at the end of the full expression ‘OpenLoco::Localisation::getDescriptorForLanguage(std::__cxx11::basic_string<char>(OpenLoco::Config::get().OpenLoco::Config::NewConfig::language))’
 1351 |             auto& language = Localisation::getDescriptorForLanguage(Config::get().language);
      |                              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
At global scope:
cc1plus: note: unrecognized command-line option ‘-Wno-unused-private-field’ may have been intended to silence earlier diagnostics
@AaronVanGeffen AaronVanGeffen added the investigate Not sure what the problem is yet label May 15, 2023
@AaronVanGeffen
Copy link
Member Author

I'm getting these warnings in libfmt as well. Would it be an option to disable these warnings for libfmt exclusively, or perhaps even globally?

@duncanspumpkin
Copy link
Contributor

I'm getting these warnings in libfmt as well. Would it be an option to disable these warnings for libfmt exclusively, or perhaps even globally?

we can just update libfmt fmtlib/fmt#3415

@AaronVanGeffen
Copy link
Member Author

AaronVanGeffen commented May 18, 2023

From that same thread:

GCC will temporarily move the warning to -Wextra

https://gcc.gnu.org/git/gitweb.cgi?p=gcc.git;h=6b927b1297e66e26e62e722bf15c921dcbbd25b9

Currently it's producing many false positives.

Hoping the next point release won't be too far off then.

@AaronVanGeffen AaronVanGeffen added build and removed investigate Not sure what the problem is yet labels May 19, 2023
@Brensom
Copy link

Brensom commented Jun 14, 2023

I have the same problem:

/home/qwerty/building/openloco/src/OpenLoco-23.06/src/Diagnostics/src/LogTerminal.cpp:68:36:   required from here
/home/qwerty/building/openloco/src/OpenLoco-23.06/build/_deps/fmt-src/include/fmt/core.h:1735:15: error: possibly dangling reference to a temporary [-Werror=dangling-reference]
 1735 |   const auto& arg = arg_mapper<Context>().map(FMT_FORWARD(val));
      |               ^~~
/home/qwerty/building/openloco/src/OpenLoco-23.06/build/_deps/fmt-src/include/fmt/core.h:1735:46: note: the temporary was destroyed at the end of the full expression ‘fmt::v9::detail::arg_mapper<fmt::v9::basic_format_context<fmt::v9::appender, char> >().fmt::v9::detail::arg_mapper<fmt::v9::basic_format_context<fmt::v9::appender, char> >::map<tm&>((* & val))’
 1735 |   const auto& arg = arg_mapper<Context>().map(FMT_FORWARD(val));
      |                     ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
In file included from /home/qwerty/building/openloco/src/OpenLoco-23.06/build/_deps/fmt-src/include/fmt/format.h:48,
                 from /home/qwerty/building/openloco/src/OpenLoco-23.06/src/Diagnostics/include/OpenLoco/Diagnostics/LogSink.h:4,
                 from /home/qwerty/building/openloco/src/OpenLoco-23.06/src/Diagnostics/include/OpenLoco/Diagnostics/LogFile.h:4,
                 from /home/qwerty/building/openloco/src/OpenLoco-23.06/src/Diagnostics/src/LogFile.cpp:1:
/home/qwerty/building/openloco/src/OpenLoco-23.06/build/_deps/fmt-src/include/fmt/core.h: In instantiation of ‘constexpr fmt::v9::detail::value<Context> fmt::v9::detail::make_value(T&&) [with Context = fmt::v9::basic_format_context<fmt::v9::appender, char>; T = tm&]’:
/home/qwerty/building/openloco/src/OpenLoco-23.06/build/_deps/fmt-src/include/fmt/core.h:1777:29:   required from ‘constexpr fmt::v9::detail::value<Context> fmt::v9::detail::make_arg(T&&) [with bool IS_PACKED = true; Context = fmt::v9::basic_format_context<fmt::v9::appender, char>; type <anonymous> = fmt::v9::detail::type::custom_type; T = tm&; typename std::enable_if<IS_PACKED, int>::type <anonymous> = 0]’
/home/qwerty/building/openloco/src/OpenLoco-23.06/build/_deps/fmt-src/include/fmt/core.h:1901:77:   required from ‘constexpr fmt::v9::format_arg_store<Context, Args>::format_arg_store(T&& ...) [with T = {tm&}; Context = fmt::v9::basic_format_context<fmt::v9::appender, char>; Args = {tm}]’
/home/qwerty/building/openloco/src/OpenLoco-23.06/build/_deps/fmt-src/include/fmt/core.h:1918:31:   required from ‘constexpr fmt::v9::format_arg_store<Context, typename std::remove_cv<typename std::remove_reference<Args>::type>::type ...> fmt::v9::make_format_args(Args&& ...) [with Context = basic_format_context<appender, char>; Args = {tm&}]’
/home/qwerty/building/openloco/src/OpenLoco-23.06/build/_deps/fmt-src/include/fmt/core.h:3206:44:   required from ‘std::string fmt::v9::format(format_string<T ...>, T&& ...) [with T = {tm}; std::string = std::__cxx11::basic_string<char>; format_string<T ...> = basic_format_string<char, tm>]’
/home/qwerty/building/openloco/src/OpenLoco-23.06/src/Diagnostics/src/LogFile.cpp:31:36:   required from here
/home/qwerty/building/openloco/src/OpenLoco-23.06/build/_deps/fmt-src/include/fmt/core.h:1735:15: error: possibly dangling reference to a temporary [-Werror=dangling-reference]
 1735 |   const auto& arg = arg_mapper<Context>().map(FMT_FORWARD(val));
      |               ^~~
/home/qwerty/building/openloco/src/OpenLoco-23.06/build/_deps/fmt-src/include/fmt/core.h:1735:46: note: the temporary was destroyed at the end of the full expression ‘fmt::v9::detail::arg_mapper<fmt::v9::basic_format_context<fmt::v9::appender, char> >().fmt::v9::detail::arg_mapper<fmt::v9::basic_format_context<fmt::v9::appender, char> >::map<tm&>((* & val))’
 1735 |   const auto& arg = arg_mapper<Context>().map(FMT_FORWARD(val));
      |                     ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
cc1plus: note: unrecognized command-line option ‘-Wno-unused-private-field’ may have been intended to silence earlier diagnostics
cc1plus: all warnings being treated as errors
make[2]: *** [src/Diagnostics/CMakeFiles/Diagnostics.dir/build.make:104: src/Diagnostics/CMakeFiles/Diagnostics.dir/src/LogTerminal.cpp.o] Error 1
make[2]: *** Waiting for unfinished jobs....
cc1plus: note: unrecognized command-line option ‘-Wno-unused-private-field’ may have been intended to silence earlier diagnostics
cc1plus: all warnings being treated as errors
make[2]: *** [src/Diagnostics/CMakeFiles/Diagnostics.dir/build.make:76: src/Diagnostics/CMakeFiles/Diagnostics.dir/src/LogFile.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:579: src/Diagnostics/CMakeFiles/Diagnostics.dir/all] Error 2

@AaronVanGeffen
Copy link
Member Author

@Brensom A workaround is to pass -DSTRICT=Off when invoking cmake. That will disable -Werror, so compiling should work at least.

@AaronVanGeffen
Copy link
Member Author

These have all been addressed in the past week, I believe.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants