diff options
author | Kaelyn Uhrain <rikka@google.com> | 2011-10-10 18:01:37 +0000 |
---|---|---|
committer | Kaelyn Uhrain <rikka@google.com> | 2011-10-10 18:01:37 +0000 |
commit | 1a6eb99d45e554ea5431d49c5cbcab4fc3d9f70e (patch) | |
tree | d89d48c4f477cadc4f51a8bf433ce1959ff3dc5e /clang/lib/Sema | |
parent | 7571ba7015d18d715f686f8a4163c1ef412694a5 (diff) | |
download | bcm5719-llvm-1a6eb99d45e554ea5431d49c5cbcab4fc3d9f70e.tar.gz bcm5719-llvm-1a6eb99d45e554ea5431d49c5cbcab4fc3d9f70e.zip |
Give nicer note when a member redeclaration has or lacks 'const'
llvm-svn: 141555
Diffstat (limited to 'clang/lib/Sema')
-rw-r--r-- | clang/lib/Sema/SemaDecl.cpp | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index b1e4a4e75b1..671ba615a85 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -4365,10 +4365,17 @@ static void DiagnoseInvalidRedeclaration(Sema &S, FunctionDecl *NewFD, 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 @@ static void DiagnoseInvalidRedeclaration(Sema &S, FunctionDecl *NewFD, << 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); } |