diff options
author | Olivier Goffart <ogoffart@woboq.com> | 2016-06-16 21:39:46 +0000 |
---|---|---|
committer | Olivier Goffart <ogoffart@woboq.com> | 2016-06-16 21:39:46 +0000 |
commit | 12b22198417c1eb83780f0905d8e466c2d774380 (patch) | |
tree | 49362a359ec199e729e38d4f2fbc29137197e68d /clang/lib/Sema/SemaLookup.cpp | |
parent | 979cb8887070437245313bf856a310a6cac5ef19 (diff) | |
download | bcm5719-llvm-12b22198417c1eb83780f0905d8e466c2d774380.tar.gz bcm5719-llvm-12b22198417c1eb83780f0905d8e466c2d774380.zip |
Functions declared in a scope should not hide previous declaration in earlier scopes
This code should be an error:
void foo(int);
void f3() {
int foo(float);
{
float foo(int); // expected-error {{functions that differ only in their return type cannot be overloaded}}
}
}
the foo(float) function declared at function scope should not hide the float(int)
while trying to redeclare functions.
Differential Revision: http://reviews.llvm.org/D19763
llvm-svn: 272961
Diffstat (limited to 'clang/lib/Sema/SemaLookup.cpp')
-rw-r--r-- | clang/lib/Sema/SemaLookup.cpp | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/clang/lib/Sema/SemaLookup.cpp b/clang/lib/Sema/SemaLookup.cpp index e761436683e..37db9aec637 100644 --- a/clang/lib/Sema/SemaLookup.cpp +++ b/clang/lib/Sema/SemaLookup.cpp @@ -1078,32 +1078,35 @@ bool Sema::CppLookupName(LookupResult &R, Scope *S) { for (; S && !isNamespaceOrTranslationUnitScope(S); S = S->getParent()) { DeclContext *Ctx = S->getEntity(); - + bool SearchNamespaceScope = true; // Check whether the IdResolver has anything in this scope. - bool Found = false; for (; I != IEnd && S->isDeclScope(*I); ++I) { if (NamedDecl *ND = R.getAcceptableDecl(*I)) { - if (NameKind == LookupRedeclarationWithLinkage) { + if (NameKind == LookupRedeclarationWithLinkage && + !(*I)->isTemplateParameter()) { + // If it's a template parameter, we still find it, so we can diagnose + // the invalid redeclaration. + // Determine whether this (or a previous) declaration is // out-of-scope. if (!LeftStartingScope && !Initial->isDeclScope(*I)) LeftStartingScope = true; // If we found something outside of our starting scope that - // does not have linkage, skip it. If it's a template parameter, - // we still find it, so we can diagnose the invalid redeclaration. - if (LeftStartingScope && !((*I)->hasLinkage()) && - !(*I)->isTemplateParameter()) { + // does not have linkage, skip it. + if (LeftStartingScope && !((*I)->hasLinkage())) { R.setShadowed(); continue; } + } else { + // We found something in this scope, we should not look at the + // namespace scope + SearchNamespaceScope = false; } - - Found = true; R.addDecl(ND); } } - if (Found) { + if (!SearchNamespaceScope) { R.resolveKind(); if (S->isClassScope()) if (CXXRecordDecl *Record = dyn_cast_or_null<CXXRecordDecl>(Ctx)) |