]> granicus.if.org Git - clang/commitdiff
Improve diagnostics for the "type qualifier on return type has no
authorDouglas Gregor <dgregor@apple.com>
Tue, 13 Jul 2010 08:50:30 +0000 (08:50 +0000)
committerDouglas Gregor <dgregor@apple.com>
Tue, 13 Jul 2010 08:50:30 +0000 (08:50 +0000)
effect warning" by printing the qualifiers we saw and correctly
pluralizing the message, e.g.,

test/SemaCXX/conditional-expr.cpp:295:3: warning: 'const volatile' type
      qualifiers on return type have no effect
  const volatile Enum g2() {
  ^~~~~ ~~~~~~~~

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

include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaType.cpp
test/SemaCXX/conditional-expr.cpp
test/SemaCXX/friend.cpp

index edd0dcb9159a25d650ccdbfeb59a7488756bf453..d73f80a2e9ccc7bd038b92df6da2cf852e95a60d 100644 (file)
@@ -121,7 +121,7 @@ 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< 
-  "type qualifier on return type has no effect">;
+  "'%0' type qualifier%s1 on return type %plural{1:has|:have}1 no effect">;
 
 def warn_decl_shadow :
   Warning<"declaration shadows a %select{"
index dc3cea1a3c5a85435521a419877daf8272253d3e..a4fc98cd958ed5e128d19ee6e7fcd7b4911a492e 100644 (file)
@@ -1135,17 +1135,34 @@ TypeSourceInfo *Sema::GetTypeForDeclarator(Declarator &D, Scope *S,
           (!getLangOptions().CPlusPlus ||
            (!T->isDependentType() && !T->isRecordType()))) {
         unsigned Quals = D.getDeclSpec().getTypeQualifiers();
+        std::string QualStr;
+        unsigned NumQuals = 0;
         SourceLocation Loc;
-        if (Quals & Qualifiers::Const)
+        if (Quals & Qualifiers::Const) {
           Loc = D.getDeclSpec().getConstSpecLoc();
-        else if (Quals & Qualifiers::Volatile)
-          Loc = D.getDeclSpec().getVolatileSpecLoc();
-        else {
-          assert((Quals & Qualifiers::Restrict) && "Unknown type qualifier");
-          Loc = D.getDeclSpec().getRestrictSpecLoc();
+          ++NumQuals;
+          QualStr = "const";
+        }
+        if (Quals & Qualifiers::Volatile) {
+          if (NumQuals == 0) {
+            Loc = D.getDeclSpec().getVolatileSpecLoc();
+            QualStr = "volatile";
+          } else
+            QualStr += " volatile";
+          ++NumQuals;
         }
-        
+        if (Quals & Qualifiers::Restrict) {
+          if (NumQuals == 0) {
+            Loc = D.getDeclSpec().getRestrictSpecLoc();
+            QualStr = "restrict";
+          } else
+            QualStr += " restrict";
+          ++NumQuals;
+        }
+        assert(NumQuals > 0 && "No known qualifiers?");
+            
         SemaDiagnosticBuilder DB = Diag(Loc, diag::warn_qual_return_type);
+        DB << QualStr << NumQuals;
         if (Quals & Qualifiers::Const)
           DB << FixItHint::CreateRemoval(D.getDeclSpec().getConstSpecLoc());
         if (Quals & Qualifiers::Volatile)
index 9cbc324467887d6e792521a05f9685888be28134..f37ccc8a15da62c60ab1da0a6fef23a388ec1f02 100644 (file)
@@ -292,10 +292,15 @@ namespace PR7598 {
     return v;
   }
 
+  const volatile Enum g2() { // expected-warning{{'const volatile' type qualifiers on return type have no effect}}
+    return v;
+  }
+
   void f() {
     const Enum v2 = v;
     Enum e = false ? g() : v;
     Enum e2 = false ? v2 : v;
+    Enum e3 = false ? g2() : v;
   }
 
 }
index ba34efe36c2fe44f5ba9713a080c22049fb5a2f5..65e0da761cfd4ab4ceebde1e4e2a7bd89e43bba2 100644 (file)
@@ -44,7 +44,7 @@ namespace test2 {
 // PR5134
 namespace test3 {
   class Foo {
-    friend const int getInt(int inInt = 0);   // expected-warning{{type qualifier on return type has no effect}}
+    friend const int getInt(int inInt = 0);   // expected-warning{{'const' type qualifier on return type has no effect}}
 
   };
 }