aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorKaelyn Uhrain <rikka@google.com>2011-10-10 18:01:37 +0000
committerKaelyn Uhrain <rikka@google.com>2011-10-10 18:01:37 +0000
commit1055393814ac989727aa7437a5f3c3c44b4f83e5 (patch)
tree2ee8cf4463585c6c973fb743988987197fd4b976 /lib
parent36bc2c663f600e7c9dc1a800d36f16603ca3ea51 (diff)
Give nicer note when a member redeclaration has or lacks 'const'
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@141555 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/Sema/SemaDecl.cpp12
1 files changed, 11 insertions, 1 deletions
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index b1e4a4e75b..671ba615a8 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/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);
}