]> granicus.if.org Git - clang/commitdiff
Wire up '-Wignored-qualifiers' to the warning on 'const' in 'const int f()'.
authorChandler Carruth <chandlerc@gmail.com>
Wed, 14 Jul 2010 06:36:18 +0000 (06:36 +0000)
committerChandler Carruth <chandlerc@gmail.com>
Wed, 14 Jul 2010 06:36:18 +0000 (06:36 +0000)
This flag and warning match GCC semantics. Also, move it to -Wextra as this is
a largely cosmetic issue and doesn't seem to mask problems. Subsequent fixes to
the tests which no longer by default emit the warning. Added explicit test
cases for both C and C++ behavior with the warning turned on.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@108325 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticGroups.td
include/clang/Basic/DiagnosticSemaKinds.td
test/Sema/block-call.c
test/Sema/block-return.c
test/Sema/return.c
test/Sema/struct-cast.c
test/SemaCXX/ambig-user-defined-conversions.cpp
test/SemaCXX/conditional-expr.cpp
test/SemaCXX/friend.cpp
test/SemaCXX/return.cpp
test/SemaTemplate/deduction.cpp

index 930fe422cff0a529d33d4da97f9cd111a9f921df..49077513c137e21f00ee41f9ee0d0d41b19493cb 100644 (file)
@@ -48,6 +48,7 @@ def CXXHexFloats : DiagGroup<"c++-hex-floats">;
 def : DiagGroup<"c++0x-compat", [CXXHexFloats]>;
 def FourByteMultiChar : DiagGroup<"four-char-constants">;
 def : DiagGroup<"idiomatic-parentheses">;
+def IgnoredQualifiers : DiagGroup<"ignored-qualifiers">;
 def : DiagGroup<"import">;
 def : DiagGroup<"init-self">;
 def : DiagGroup<"inline">;
@@ -167,6 +168,7 @@ def Format2 : DiagGroup<"format=2",
 
 def Extra : DiagGroup<"extra", [
     MissingFieldInitializers,
+    IgnoredQualifiers,
     InitializerOverrides,
     SemiBeforeMethodBody,
     SignCompare,
index f6542afa0797ac1cb9583890c857f9294c3b9b7b..01a37fb6f2c63a4955c36d3016fb812e550e0fac 100644 (file)
@@ -121,7 +121,8 @@ def warn_use_out_of_scope_declaration : Warning<
 def err_inline_non_function : Error<
   "'inline' can only appear on functions">;
 def warn_qual_return_type : Warning< 
-  "'%0' type qualifier%s1 on return type %plural{1:has|:have}1 no effect">;
+  "'%0' type qualifier%s1 on return type %plural{1:has|:have}1 no effect">,
+  InGroup<IgnoredQualifiers>, DefaultIgnore;
 
 def warn_decl_shadow :
   Warning<"declaration shadows a %select{"
index 28e6c68a8006900cd8af863480b63663f5913b26..27e4cfc6d46b8509830bffc14012b1663044d8d8 100644 (file)
@@ -13,10 +13,9 @@ int main() {
   int (^IFP) () = PFR; // OK
 
 
-  const int (^CIC) () = IFP; // expected-error {{incompatible block pointer types initializing 'int const (^)()' with an expression of type 'int (^)()'}} \
-  // expected-warning{{type qualifier on return type has no effect}}
+  const int (^CIC) () = IFP; // expected-error {{incompatible block pointer types initializing 'int const (^)()' with an expression of type 'int (^)()'}}
 
-  const int (^CICC) () = CIC;   // expected-warning{{type qualifier on return type has no effect}}
+  const int (^CICC) () = CIC;
 
 
   int * const (^IPCC) () = 0;
index 33fd183be069e8fb30cd3cca8f468b08b9660b69..5a4ec010d3a2113b358e1f9fc8024ac7daf35323 100644 (file)
@@ -109,10 +109,9 @@ void foo6() {
 
 void foo7()
 {
- const int (^BB) (void) = ^{ const int i = 1; return i; }; // expected-error{{incompatible block pointer types initializing 'int const (^)(void)' with an expression of type 'int (^)(void)'}} \
- // expected-warning{{type qualifier on return type has no effect}}
+ const int (^BB) (void) = ^{ const int i = 1; return i; }; // expected-error{{incompatible block pointer types initializing 'int const (^)(void)' with an expression of type 'int (^)(void)'}}
 
- const int (^CC) (void)  = ^const int{ const int i = 1; return i; }; // expected-warning{{type qualifier on return type has no effect}}
+ const int (^CC) (void)  = ^const int{ const int i = 1; return i; };
 
 
   int i;
index 2d23e080396799eaaa6f7b22e78b510ccf71ba23..54c340634d39850d7907aaf346f93930f62e5666 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: %clang %s -fsyntax-only -Wreturn-type -Xclang -verify -fblocks -Wno-unreachable-code -Wno-unused-value
+// RUN: %clang %s -fsyntax-only -Wignored-qualifiers -Wreturn-type -Xclang -verify -fblocks -Wno-unreachable-code -Wno-unused-value
 
 // clang emits the following warning by default.
 // With GCC, -pedantic, -Wreturn-type or -Wall are required to produce the 
@@ -239,3 +239,6 @@ int test_static_inline(int x) {
 }
 static inline int si_forward() {} // expected-warning{{control reaches end of non-void function}}
 
+// Test warnings on ignored qualifiers on return types.
+const int ignored_c_quals(); // expected-warning{{'const' type qualifier on return type has no effect}}
+const volatile int ignored_cv_quals(); // expected-warning{{'const volatile' type qualifiers on return type have no effect}}
index 3456665a8c55fc19c46929517a129a273691605f..30ef89242afcc2fcd6f6f222bc1810bf7f9ee0ea 100644 (file)
@@ -5,7 +5,7 @@ struct S {
  int two;
 };
 
-struct S const foo(void);  // expected-warning{{type qualifier on return type has no effect}}
+struct S const foo(void);
 
 
 struct S tmp;
index 9811859fccce0fda58a1b1115c8593f3115447d1..fdb399b03a2168f6a0fe1e7b4f52d117134c83cb 100644 (file)
@@ -17,7 +17,7 @@ namespace test0 {
   void func(const char ci, const B b); // expected-note {{candidate function}}
   void func(const B b, const int ci); // expected-note {{candidate function}}
 
-  const int Test1() { // expected-warning{{type qualifier on return type has no effect}}
+  const int Test1() {
 
     func(b1, f()); // expected-error {{call to 'func' is ambiguous}}
     return f(); // expected-error {{conversion from 'test0::B' to 'int const' is ambiguous}}
index f37ccc8a15da62c60ab1da0a6fef23a388ec1f02..065179b6da59d3b9c970c6a7f854ff8dd11a16ad 100644 (file)
@@ -288,11 +288,11 @@ namespace PR7598 {
     v = 1,
   };
 
-  const Enum g() { // expected-warning{{type qualifier on return type has no effect}}
+  const Enum g() {
     return v;
   }
 
-  const volatile Enum g2() { // expected-warning{{'const volatile' type qualifiers on return type have no effect}}
+  const volatile Enum g2() {
     return v;
   }
 
index 65e0da761cfd4ab4ceebde1e4e2a7bd89e43bba2..30abcbbeaa528b1a2be61f5eaad76626d9582a46 100644 (file)
@@ -44,7 +44,7 @@ namespace test2 {
 // PR5134
 namespace test3 {
   class Foo {
-    friend const int getInt(int inInt = 0);   // expected-warning{{'const' type qualifier on return type has no effect}}
+    friend const int getInt(int inInt = 0);
 
   };
 }
index e682fdfb500921dfec01f8356376f588e9038443..6bdbe52727b247c6698eb806c218e64269dd411e 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 %s -fsyntax-only -verify
+// RUN: %clang_cc1 %s -fsyntax-only -Wignored-qualifiers -verify
 
 int test1() {
   throw;
@@ -16,3 +16,13 @@ template<typename T>
 T h() {
   return 17;
 }
+
+// Don't warn on cv-qualified class return types, only scalar return types.
+namespace ignored_quals {
+struct S {};
+const S class_c();
+const volatile S class_cv();
+
+const int scalar_c(); // expected-warning{{'const' type qualifier on return type has no effect}}
+const volatile int scalar_cv(); // expected-warning{{'const volatile' type qualifiers on return type have no effect}}
+}
index 25ffb67492a564f9cba146d09770e7943179c194..e8ff8d3a6d24fe6f31c4ae87defad5a3794464da 100644 (file)
@@ -101,7 +101,7 @@ namespace PR6257 {
 
 // PR7463
 namespace PR7463 {
-  const int f (); // expected-warning{{type qualifier on return type has no effect}}
+  const int f ();
   template <typename T_> void g (T_&); // expected-note{{T_ = int}}
   void h (void) { g(f()); } // expected-error{{no matching function for call}}
 }