Commit 7d03534
committed
[CMake] Disable -Wdangling-reference warnings on GCC
This gets rid of 99 warnings which mostly seem like false positives
(in a build of LLVM+Clang+LLDB).
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>`.1 parent be6f110 commit 7d03534
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