Commit e741b71
authored
[CMake] Disable -Wdangling-reference warnings on GCC (llvm#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.1 parent 68830c7 commit e741b71
1 file changed
+8
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
889 | 889 | | |
890 | 890 | | |
891 | 891 | | |
| 892 | + | |
| 893 | + | |
| 894 | + | |
| 895 | + | |
| 896 | + | |
| 897 | + | |
| 898 | + | |
| 899 | + | |
892 | 900 | | |
893 | 901 | | |
894 | 902 | | |
| |||
0 commit comments