https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110075
Bug ID: 110075 Summary: Bogus -Wdangling-reference Product: gcc Version: 13.1.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: pilarlatiesa at gmail dot com Target Milestone: --- $ cat test.cpp #include <map> #include <string> class T { static inline std::map<std::string, int> const m = {{"foo", 0}}; public: static int const &Get(std::string const &s) { return m.at(s); } }; int main() { [[maybe_unused]] int const &i = T::Get("foo"); } $ ./gcc-13/bin/g++ -Wall test.cpp test.cpp: In function ‘int main()’: test.cpp:14:31: warning: possibly dangling reference to a temporary [-Wdangling-reference] 14 | [[maybe_unused]] int const &i = T::Get("foo"); | ^ test.cpp:14:41: note: the temporary was destroyed at the end of the full expression ‘T::Get(std::__cxx11::basic_string<char>(((const char*)"foo"), std::allocator<char>()))’ 14 | [[maybe_unused]] int const &i = T::Get("foo"); | ~~~~~~^~~~~~~