https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107532
Bug ID: 107532 Summary: [13 Regression] -Werror=dangling-reference false positives in libcamera-0.0.1 Product: gcc Version: 13.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: slyfox at gcc dot gnu.org CC: mpolacek at gcc dot gnu.org Target Milestone: --- libcamera-0.0.1 and a few other projects (like cvise) fail to compile due to -Werror on -Werror=dangling-reference. I think those are false positives related to value-like types that pass references through. Extracted example from libcamera: // $ cat a.cpp.cpp struct Plane { unsigned int bytesused; }; // Passes a reference through. Does not change lifetime. template <typename Inner> struct Ref { const Inner & i_; Ref(const Inner & i) : i_(i) {} const Inner & inner() { return i_; } }; struct FrameMetadata { Ref<const Plane> planes() const { return p_; } Plane p_; }; void bar(const Plane & meta); void foo(const FrameMetadata & fm) { const Plane & meta = fm.planes().inner(); bar(meta); } $ g++-13.0.0 -c -Wall -Werror=dangling-reference a.cpp a.cpp: In function 'void foo(const FrameMetadata&)': a.cpp:20:19: error: possibly dangling reference to a temporary [-Werror=dangling-reference] 20 | const Plane & meta = fm.planes().inner(); | ^~~~ a.cpp:20:43: note: the temporary was destroyed at the end of the full expression '(& fm)->FrameMetadata::planes().Ref<const Plane>::inner()' 20 | const Plane & meta = fm.planes().inner(); | ~~~~~~~~~~~~~~~~~^~ cc1plus: some warnings being treated as errors This gcc version is this week's gcc-13 snapshot with https://gcc.gnu.org/PR107488 applied on top.