[cfe-commits] r108236 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaType.cpp test/SemaCXX/conditional-expr.cpp test/SemaCXX/friend.cpp

Douglas Gregor dgregor at apple.com
Tue Jul 13 01:50:30 PDT 2010


Author: dgregor
Date: Tue Jul 13 03:50:30 2010
New Revision: 108236

URL: http://llvm.org/viewvc/llvm-project?rev=108236&view=rev
Log:
Improve diagnostics for the "type qualifier on return type has no
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() {
  ^~~~~ ~~~~~~~~




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

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=108236&r1=108235&r2=108236&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue Jul 13 03:50:30 2010
@@ -121,7 +121,7 @@
 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{"

Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=108236&r1=108235&r2=108236&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Tue Jul 13 03:50:30 2010
@@ -1135,17 +1135,34 @@
           (!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)

Modified: cfe/trunk/test/SemaCXX/conditional-expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/conditional-expr.cpp?rev=108236&r1=108235&r2=108236&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/conditional-expr.cpp (original)
+++ cfe/trunk/test/SemaCXX/conditional-expr.cpp Tue Jul 13 03:50:30 2010
@@ -292,10 +292,15 @@
     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;
   }
 
 }

Modified: cfe/trunk/test/SemaCXX/friend.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/friend.cpp?rev=108236&r1=108235&r2=108236&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/friend.cpp (original)
+++ cfe/trunk/test/SemaCXX/friend.cpp Tue Jul 13 03:50:30 2010
@@ -44,7 +44,7 @@
 // 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}}
 
   };
 }





More information about the cfe-commits mailing list