[cfe-commits] r108325 - in /cfe/trunk: 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

Chandler Carruth chandlerc at gmail.com
Tue Jul 13 23:36:18 PDT 2010


Author: chandlerc
Date: Wed Jul 14 01:36:18 2010
New Revision: 108325

URL: http://llvm.org/viewvc/llvm-project?rev=108325&view=rev
Log:
Wire up '-Wignored-qualifiers' to the warning on 'const' in 'const int f()'.
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.

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

Modified: cfe/trunk/include/clang/Basic/DiagnosticGroups.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticGroups.td?rev=108325&r1=108324&r2=108325&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticGroups.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticGroups.td Wed Jul 14 01:36:18 2010
@@ -48,6 +48,7 @@
 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 Extra : DiagGroup<"extra", [
     MissingFieldInitializers,
+    IgnoredQualifiers,
     InitializerOverrides,
     SemiBeforeMethodBody,
     SignCompare,

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=108325&r1=108324&r2=108325&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Wed Jul 14 01:36:18 2010
@@ -121,7 +121,8 @@
 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{"

Modified: cfe/trunk/test/Sema/block-call.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/block-call.c?rev=108325&r1=108324&r2=108325&view=diff
==============================================================================
--- cfe/trunk/test/Sema/block-call.c (original)
+++ cfe/trunk/test/Sema/block-call.c Wed Jul 14 01:36:18 2010
@@ -13,10 +13,9 @@
   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;

Modified: cfe/trunk/test/Sema/block-return.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/block-return.c?rev=108325&r1=108324&r2=108325&view=diff
==============================================================================
--- cfe/trunk/test/Sema/block-return.c (original)
+++ cfe/trunk/test/Sema/block-return.c Wed Jul 14 01:36:18 2010
@@ -109,10 +109,9 @@
 
 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;

Modified: cfe/trunk/test/Sema/return.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/return.c?rev=108325&r1=108324&r2=108325&view=diff
==============================================================================
--- cfe/trunk/test/Sema/return.c (original)
+++ cfe/trunk/test/Sema/return.c Wed Jul 14 01:36:18 2010
@@ -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 @@
 }
 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}}

Modified: cfe/trunk/test/Sema/struct-cast.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/struct-cast.c?rev=108325&r1=108324&r2=108325&view=diff
==============================================================================
--- cfe/trunk/test/Sema/struct-cast.c (original)
+++ cfe/trunk/test/Sema/struct-cast.c Wed Jul 14 01:36:18 2010
@@ -5,7 +5,7 @@
  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;

Modified: cfe/trunk/test/SemaCXX/ambig-user-defined-conversions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/ambig-user-defined-conversions.cpp?rev=108325&r1=108324&r2=108325&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/ambig-user-defined-conversions.cpp (original)
+++ cfe/trunk/test/SemaCXX/ambig-user-defined-conversions.cpp Wed Jul 14 01:36:18 2010
@@ -17,7 +17,7 @@
   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}}

Modified: cfe/trunk/test/SemaCXX/conditional-expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/conditional-expr.cpp?rev=108325&r1=108324&r2=108325&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/conditional-expr.cpp (original)
+++ cfe/trunk/test/SemaCXX/conditional-expr.cpp Wed Jul 14 01:36:18 2010
@@ -288,11 +288,11 @@
     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;
   }
 

Modified: cfe/trunk/test/SemaCXX/friend.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/friend.cpp?rev=108325&r1=108324&r2=108325&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/friend.cpp (original)
+++ cfe/trunk/test/SemaCXX/friend.cpp Wed Jul 14 01:36:18 2010
@@ -44,7 +44,7 @@
 // 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);
 
   };
 }

Modified: cfe/trunk/test/SemaCXX/return.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/return.cpp?rev=108325&r1=108324&r2=108325&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/return.cpp (original)
+++ cfe/trunk/test/SemaCXX/return.cpp Wed Jul 14 01:36:18 2010
@@ -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 @@
 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}}
+}

Modified: cfe/trunk/test/SemaTemplate/deduction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/deduction.cpp?rev=108325&r1=108324&r2=108325&view=diff
==============================================================================
--- cfe/trunk/test/SemaTemplate/deduction.cpp (original)
+++ cfe/trunk/test/SemaTemplate/deduction.cpp Wed Jul 14 01:36:18 2010
@@ -101,7 +101,7 @@
 
 // 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}}
 }





More information about the cfe-commits mailing list