You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[CMake] Disable -Wdangling-reference warnings on GCC (#157541)
This gets rid of 99 warnings which mostly seem like false positives (in
a build of LLVM+Clang+LLDB, with GCC 13).
The warnings look e.g. like this:
../lib/ObjCopy/COFF/COFFObjcopy.cpp: In function ‘uint64_t
llvm::objcopy::coff::getNextRVA(const Object&)’:
../lib/ObjCopy/COFF/COFFObjcopy.cpp:38:18: warning: possibly dangling
reference to a temporary [-Wdangling-reference]
38 | const Section &Last = Obj.getSections().back();
| ^~~~
../lib/ObjCopy/COFF/COFFObjcopy.cpp:38:47: note: the temporary was
destroyed at the end of the full expression ‘(&
Obj)->llvm::objcopy::coff::Object::getSections().llvm::ArrayRef<llvm::objcopy::coff::Section>::back()’
38 | const Section &Last = Obj.getSections().back();
| ~~~~~~~~~~~~~~~~~~~~~~^~
In this example, the `Object::getSections()` method returns an
`ArrayRef<Section>` from a `std::vector<Section>`. We invoke `back()` on
that, and store a reference in a local variable. Even though the
temporary `ArrayRef<Section>` has been destroyed, the reference points
to something which still is alive in the `std::vector<Section>`.
See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109642 and
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110358 for some
preexisting discussion on this warning and how it can be silenced
selectively since GCC 14.
0 commit comments