]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: Move -Wdangling-reference to -Wextra [PR109642]
authorMarek Polacek <polacek@redhat.com>
Tue, 2 May 2023 19:48:40 +0000 (15:48 -0400)
committerMarek Polacek <polacek@redhat.com>
Tue, 2 May 2023 19:48:40 +0000 (15:48 -0400)
Sadly, -Wdangling-reference generates false positives for std::span-like
user classes, and it seems imprudent to attempt to improve the heuristic
in GCC 13.  Let's move the warning to -Wextra, that will hopefully
reduce the number of false positives the users have been seeing with 13.

I'm leaving the warning in -Wall in 14 where I think I can write code
to detect std::span-like classes.

PR c++/109642
PR c++/109640
PR c++/109671

gcc/c-family/ChangeLog:

* c.opt (Wdangling-reference): Move from -Wall to -Wextra.

gcc/ChangeLog:

* doc/invoke.texi: Document that -Wdangling-reference is
enabled by -Wextra.

gcc/c-family/c.opt
gcc/doc/invoke.texi

index 3333cddeece7e3920bd903eca7ab5e28411be1d2..a75038930aefa2fac910b520d5c2b55e66936a3d 100644 (file)
@@ -560,7 +560,7 @@ C ObjC C++ ObjC++ Joined RejectNegative UInteger Var(warn_dangling_pointer) Warn
 Warn for uses of pointers to auto variables whose lifetime has ended.
 
 Wdangling-reference
-C++ ObjC++ Var(warn_dangling_reference) Warning LangEnabledBy(C++ ObjC++, Wall)
+C++ ObjC++ Var(warn_dangling_reference) Warning LangEnabledBy(C++ ObjC++, Wextra)
 Warn when a reference is bound to a temporary whose lifetime has ended.
 
 Wdate-time
index a38547f53e53563784fb85a3aa78ae44785955c0..36ed159144096e9aec19584a2524b4b7b8725072 100644 (file)
@@ -3781,7 +3781,7 @@ where @code{std::minmax} returns @code{std::pair<const int&, const int&>}, and
 both references dangle after the end of the full expression that contains
 the call to @code{std::minmax}.
 
-This warning is enabled by @option{-Wall}.
+This warning is enabled by @option{-Wextra}.
 
 @opindex Wdelete-non-virtual-dtor
 @opindex Wno-delete-non-virtual-dtor
@@ -6126,6 +6126,7 @@ name is still supported, but the newer name is more descriptive.)
 
 @gccoptlist{-Wclobbered
 -Wcast-function-type
+-Wdangling-reference @r{(C++ only)}
 -Wdeprecated-copy @r{(C++ only)}
 -Wempty-body
 -Wenum-conversion @r{(C only)}