]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR middle-end/7651 (Define -Wextra strictly in terms of other warning flags)
authorManuel López-Ibáñez <manu@gcc.gnu.org>
Fri, 8 Aug 2008 23:32:23 +0000 (23:32 +0000)
committerManuel López-Ibáñez <manu@gcc.gnu.org>
Fri, 8 Aug 2008 23:32:23 +0000 (23:32 +0000)
2008-08-09  Manuel Lopez-Ibanez  <manu@gcc.gnu.org>

PR 7651
* doc/invoke.texi (-Wextra): Move warning from here...
(-Wuninitialized): ... to here.
cp/
* class.c (check_bases_and_members): Warn with -Wuninitialized
instead of -Wextra.
testsuite/
* g++.dg/warn/Wuninitializable-member.C: New.
* g++.dg/warn/Wuninitializable-member-no.C: New.

From-SVN: r138892

gcc/ChangeLog
gcc/cp/ChangeLog
gcc/cp/class.c
gcc/doc/invoke.texi
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/warn/Wuninitializable-member-no.C [new file with mode: 0644]
gcc/testsuite/g++.dg/warn/Wuninitializable-member.C [new file with mode: 0644]

index 569efd1f5b321b9df8a5a29c412f311c896de59f..8ba80b2aa3420c683f4825ff909340346ffebc4f 100644 (file)
@@ -1,3 +1,9 @@
+2008-08-09  Manuel Lopez-Ibanez  <manu@gcc.gnu.org>
+
+       PR 7651
+       * doc/invoke.texi (-Wextra): Move warning from here...
+       (-Wuninitialized): ... to here.
+       
 2008-08-08  Manuel Lopez-Ibanez  <manu@gcc.gnu.org>
 
        PR 28875
index d37f31f96fb4cd0f6bfbd01d8aa7b310aa8a9529..46370908becddca23b8617e70c16d51d82d2a0db 100644 (file)
@@ -1,3 +1,9 @@
+2008-08-09  Manuel Lopez-Ibanez  <manu@gcc.gnu.org>
+
+       PR 7651
+       * class.c (check_bases_and_members): Warn with -Wuninitialized
+       instead of -Wextra.
+       
 2008-08-08  Volker Reichelt  <v.reichelt@netcologne.de>
 
        PR c++/35985
index f7e46a717aaf49e62c821ef6621a576442ec1dee..b08f9c80d2962824be1e40befe852bd61615e340 100644 (file)
@@ -4306,7 +4306,7 @@ check_bases_and_members (tree t)
   /* If the class has no user-declared constructor, but does have
      non-static const or reference data members that can never be
      initialized, issue a warning.  */
-  if (extra_warnings
+  if (warn_uninitialized
       /* Classes with user-declared constructors are presumed to
         initialize these members.  */
       && !TYPE_HAS_USER_CONSTRUCTOR (t)
@@ -4325,13 +4325,13 @@ check_bases_and_members (tree t)
 
          type = TREE_TYPE (field);
          if (TREE_CODE (type) == REFERENCE_TYPE)
-           warning (OPT_Wextra, "non-static reference %q+#D in class "
-                    "without a constructor", field);
+           warning (OPT_Wuninitialized, "non-static reference %q+#D "
+                    "in class without a constructor", field);
          else if (CP_TYPE_CONST_P (type)
                   && (!CLASS_TYPE_P (type)
                       || !TYPE_HAS_DEFAULT_CONSTRUCTOR (type)))
-           warning (OPT_Wextra, "non-static const member %q+#D in class "
-                    "without a constructor", field);
+           warning (OPT_Wuninitialized, "non-static const member %q+#D "
+                    "in class without a constructor", field);
        }
     }
 
index cb0299585d8edd73f5663def9475912ec97cc2d8..051f6d1ff053ad8a2f98a8740e547f68d90bbe3e 100644 (file)
@@ -2748,10 +2748,6 @@ A pointer is compared against integer zero with @samp{<}, @samp{<=},
 (C++ only) An enumerator and a non-enumerator both appear in a
 conditional expression.
 
-@item 
-(C++ only) A non-static reference or non-static @samp{const} member
-appears in a class without constructors.
-
 @item 
 (C++ only) Ambiguous virtual bases.
 
@@ -3173,8 +3169,10 @@ either specify @samp{-Wextra -Wunused} (note that @samp{-Wall} implies
 @item -Wuninitialized
 @opindex Wuninitialized
 @opindex Wno-uninitialized
-Warn if an automatic variable is used without first being initialized or
-if a variable may be clobbered by a @code{setjmp} call.
+Warn if an automatic variable is used without first being initialized
+or if a variable may be clobbered by a @code{setjmp} call. In C++,
+warn if a non-static reference or non-static @samp{const} member
+appears in a class without constructors.
 
 If you want to warn about code which uses the uninitialized value of the
 variable in its own initializer, use the @option{-Winit-self} option.
index db2088fac1a161dd3fd7d28ee921c0cf04a99f63..6be4d9423f42692385c8baba81cf43820cf113b8 100644 (file)
@@ -1,3 +1,9 @@
+2008-08-09  Manuel Lopez-Ibanez  <manu@gcc.gnu.org>
+
+       PR 7651
+       * g++.dg/warn/Wuninitializable-member.C: New.
+       * g++.dg/warn/Wuninitializable-member-no.C: New.
+       
 2008-08-08  Manuel Lopez-Ibanez  <manu@gcc.gnu.org>
 
        PR 28875
diff --git a/gcc/testsuite/g++.dg/warn/Wuninitializable-member-no.C b/gcc/testsuite/g++.dg/warn/Wuninitializable-member-no.C
new file mode 100644 (file)
index 0000000..0f6ccfd
--- /dev/null
@@ -0,0 +1,15 @@
+// Test disabling
+// { dg-do compile } 
+// { dg-options "-Wall -Wextra -Wno-uninitialized" }
+
+class X {
+  int & flag;// { dg-bogus "non-static reference 'int& X::flag' in class without a constructor" }
+public:
+  void f(){ flag++ ; }
+};
+
+class Y {
+  const int var;// { dg-bogus "non-static const member 'const int Y::var' in class without a constructor" }
+public:
+  int g(){ return 2*var; }
+};
diff --git a/gcc/testsuite/g++.dg/warn/Wuninitializable-member.C b/gcc/testsuite/g++.dg/warn/Wuninitializable-member.C
new file mode 100644 (file)
index 0000000..1c37e3e
--- /dev/null
@@ -0,0 +1,14 @@
+// { dg-do compile } 
+// { dg-options "-Wuninitialized" }
+
+class X {
+  int & flag;// { dg-warning "non-static reference 'int& X::flag' in class without a constructor" }
+public:
+  void f(){ flag++ ; }
+};
+
+class Y {
+  const int var;// { dg-warning "non-static const member 'const int Y::var' in class without a constructor" }
+public:
+  int g(){ return 2*var; }
+};