[cfe-commits] r141555 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaDecl.cpp test/SemaCXX/function-redecl.cpp test/SemaCXX/nested-name-spec.cpp

Kaelyn Uhrain rikka at google.com
Mon Oct 10 11:01:37 PDT 2011


Author: rikka
Date: Mon Oct 10 13:01:37 2011
New Revision: 141555

URL: http://llvm.org/viewvc/llvm-project?rev=141555&view=rev
Log:
Give nicer note when a member redeclaration has or lacks 'const'

Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/test/SemaCXX/function-redecl.cpp
    cfe/trunk/test/SemaCXX/nested-name-spec.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=141555&r1=141554&r2=141555&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Mon Oct 10 13:01:37 2011
@@ -3253,6 +3253,9 @@
 def err_member_qualification : Error<
   "non-friend class member %0 cannot have a qualified name">;  
 def note_member_def_close_match : Note<"member declaration nearly matches">;
+def note_member_def_close_const_match : Note<
+  "member declaration does not match because "
+  "it %select{is|is not}0 const qualified">;
 def note_member_def_close_param_match : Note<
   "type of %ordinal0 parameter of member declaration does not match "
   "definition (%1 vs %2)">;

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=141555&r1=141554&r2=141555&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Mon Oct 10 13:01:37 2011
@@ -4365,10 +4365,17 @@
   else
     S.Diag(NewFD->getLocation(), DiagMsg) << Name << DC << NewFD->getLocation();
 
+  bool NewFDisConst = false;
+  if (CXXMethodDecl *NewMD = dyn_cast<CXXMethodDecl>(NewFD))
+    NewFDisConst = NewMD->getTypeQualifiers() & Qualifiers::Const;
+
   for (llvm::SmallVector<std::pair<FunctionDecl*, unsigned>, 1>::iterator
        NearMatch = NearMatches.begin(), NearMatchEnd = NearMatches.end();
        NearMatch != NearMatchEnd; ++NearMatch) {
     FunctionDecl *FD = NearMatch->first;
+    bool FDisConst = false;
+    if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD))
+      FDisConst = MD->getTypeQualifiers() & Qualifiers::Const;
 
     if (unsigned Idx = NearMatch->second) {
       ParmVarDecl *FDParam = FD->getParamDecl(Idx-1);
@@ -4377,7 +4384,10 @@
           << Idx << FDParam->getType() << NewFD->getParamDecl(Idx-1)->getType();
     } else if (Correction) {
       S.Diag(FD->getLocation(), diag::note_previous_decl)
-        << Correction.getQuoted(S.getLangOptions());
+          << Correction.getQuoted(S.getLangOptions());
+    } else if (FDisConst != NewFDisConst) {
+      S.Diag(FD->getLocation(), diag::note_member_def_close_const_match)
+          << NewFDisConst << FD->getSourceRange().getEnd();
     } else
       S.Diag(FD->getLocation(), diag::note_member_def_close_match);
   }

Modified: cfe/trunk/test/SemaCXX/function-redecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/function-redecl.cpp?rev=141555&r1=141554&r2=141555&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/function-redecl.cpp (original)
+++ cfe/trunk/test/SemaCXX/function-redecl.cpp Mon Oct 10 13:01:37 2011
@@ -62,7 +62,7 @@
 }
 
 class Bar {
-  void f(test1::Foo::Inner foo) const; // expected-note {{member declaration nearly matches}}
+  void f(test1::Foo::Inner foo) const; // expected-note {{member declaration does not match because it is const qualified}}
 };
 
 using test1::Foo;
@@ -79,3 +79,16 @@
 void Crash::cart(int count) const {} // expected-error {{out-of-line definition of 'cart' does not match any declaration in 'Crash'}}
 // ...while this one crashed clang
 void Crash::chart(int count) const {} // expected-error {{out-of-line definition of 'chart' does not match any declaration in 'Crash'}}
+
+class TestConst {
+ public:
+  int getit() const; // expected-note {{member declaration does not match because it is const qualified}}
+  void setit(int); // expected-note {{member declaration does not match because it is not const qualified}}
+};
+
+int TestConst::getit() { // expected-error {{out-of-line definition of 'getit' does not match any declaration in 'TestConst'}}
+  return 1;
+}
+
+void TestConst::setit(int) const { // expected-error {{out-of-line definition of 'setit' does not match any declaration in 'TestConst'}}
+}

Modified: cfe/trunk/test/SemaCXX/nested-name-spec.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/nested-name-spec.cpp?rev=141555&r1=141554&r2=141555&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/nested-name-spec.cpp (original)
+++ cfe/trunk/test/SemaCXX/nested-name-spec.cpp Mon Oct 10 13:01:37 2011
@@ -27,10 +27,10 @@
 static int A::C::cx2 = 17; // expected-error{{'static' can}}
 
 class C2 {
-  void m(); // expected-note{{member declaration nearly matches}}
+  void m(); // expected-note{{member declaration does not match because it is not const qualified}}
 
   void f(const int& parm); // expected-note{{type of 1st parameter of member declaration does not match definition ('const int &' vs 'int')}}
-  void f(int) const; // expected-note{{member declaration nearly matches}}
+  void f(int) const; // expected-note{{member declaration does not match because it is const qualified}}
   void f(float);
 
   int x;
@@ -121,7 +121,7 @@
 
 
 class Operators {
-  Operators operator+(const Operators&) const; // expected-note{{member declaration nearly matches}}
+  Operators operator+(const Operators&) const; // expected-note{{member declaration does not match because it is const qualified}}
   operator bool();
 };
 





More information about the cfe-commits mailing list