Skip to content

build with -Wdangling-reference #834

@maksim-harbachou-resilio

Description

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions