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

build with -Wdangling-reference #834

Open
maksim-harbachou-resilio opened this issue Jul 12, 2024 · 0 comments
Open

build with -Wdangling-reference #834

maksim-harbachou-resilio opened this issue Jul 12, 2024 · 0 comments

Comments

@maksim-harbachou-resilio

Currently build with -Wdangling-reference (g++ 14.1.0) gives the following:

.../date/include/date/date.h:6594:15: error: possibly dangling reference to a temporary [-Werror=dangling-reference]
 6594 |         auto& f = std::use_facet<std::time_get<CharT>>(is.getloc());
.../date/include/date/date.h:6594:55: note: the temporary was destroyed at the end of the full expression ‘std::use_facet<__cxx11::time_get<char> >(std::ios_base::getloc() const())’

See https://github.com/HowardHinnant/date/blob/master/include/date/date.h#L6594

The following patch fixes the issue for me:

 #if !ONLY_C_LOCALE
-        auto& f = std::use_facet<std::time_get<CharT>>(is.getloc());
+        auto loc = is.getloc();
+        auto& f = std::use_facet<std::time_get<CharT>>(loc);
         std::tm tm{};
 #endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant