[llvm] [CMake] Disable -Wdangling-reference warnings on GCC (PR #157541)
Martin Storsjö via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 9 02:20:08 PDT 2025
mstorsjo wrote:
Re upstream bug reports, I found https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109642 and https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110358 which cover the majority of our cases. The gist of it:
> std::span, std::reference_wrapper and std::ref_view are all special cased for the warning.
> > Would you consider perhaps reducing the scope of the warning in order to reduce the false positive rate, alternatively move it out of Wall?
>
> ...I think I'll have to move it to -Wextra (for GCC 13.2).
> c++: avoid -Wdangling-reference for std::span-like classes
Since GCC 14, this detects any class which looks like `std::span`, which should match ArrayRef, and avoids the warnings for them.
If compiling with GCC 15, I do see some of these warnings relating to ArrayRef to be silenced - but there's even more of them for other cases; with GCC 15, I see up to 274 of these warnings, while I "only" had 99 with GCC 13.
> c++: implement [[gnu::no_dangling]]
Since GCC 14, it's also possible to tag individual classes/functions with this attribute (classes like ArrayRef and similar), to excempt them from this warning.
I did find one odd case which did seem like a separate true false positive though, which I filed at https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121871.
https://github.com/llvm/llvm-project/pull/157541
More information about the llvm-commits
mailing list