[cfe-commits] r148154 - in /cfe/trunk: lib/Sema/SemaLookup.cpp test/Sema/function.c
Douglas Gregor
dgregor at apple.com
Fri Jan 13 15:06:53 PST 2012
Author: dgregor
Date: Fri Jan 13 17:06:53 2012
New Revision: 148154
URL: http://llvm.org/viewvc/llvm-project?rev=148154&view=rev
Log:
Make sure to consider non-DeclContext scopes properly when finding
multiple name lookup results in C/Objective-C. Fixes a regression a
caused in r147533, found by Enea Zaffanella!
Modified:
cfe/trunk/lib/Sema/SemaLookup.cpp
cfe/trunk/test/Sema/function.c
Modified: cfe/trunk/lib/Sema/SemaLookup.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaLookup.cpp?rev=148154&r1=148153&r2=148154&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaLookup.cpp (original)
+++ cfe/trunk/lib/Sema/SemaLookup.cpp Fri Jan 13 17:06:53 2012
@@ -1163,20 +1163,40 @@
// Check whether there are any other declarations with the same name
// and in the same scope.
if (I != IEnd) {
- DeclContext *DC = (*I)->getDeclContext()->getRedeclContext();
+ // Find the scope in which this declaration was declared (if it
+ // actually exists in a Scope).
+ while (S && !S->isDeclScope(D))
+ S = S->getParent();
+
+ // If the scope containing the declaration is the translation unit,
+ // then we'll need to perform our checks based on the matching
+ // DeclContexts rather than matching scopes.
+ if (S && isNamespaceOrTranslationUnitScope(S))
+ S = 0;
+
+ // Compute the DeclContext, if we need it.
+ DeclContext *DC = 0;
+ if (!S)
+ DC = (*I)->getDeclContext()->getRedeclContext();
+
IdentifierResolver::iterator LastI = I;
for (++LastI; LastI != IEnd; ++LastI) {
- DeclContext *LastDC
- = (*LastI)->getDeclContext()->getRedeclContext();
+ if (S) {
+ // Match based on scope.
+ if (!S->isDeclScope(*LastI))
+ break;
+ } else {
+ // Match based on DeclContext.
+ DeclContext *LastDC
+ = (*LastI)->getDeclContext()->getRedeclContext();
+ if (!LastDC->Equals(DC))
+ break;
+ }
+
+ // If the declaration isn't in the right namespace, skip it.
if (!(*LastI)->isInIdentifierNamespace(IDNS))
continue;
-
- if (!LastDC->Equals(DC))
- break;
-
- if (!LastDC->isFileContext() && !S->isDeclScope(*LastI))
- break;
-
+
D = R.isHiddenDeclarationVisible()? *LastI : getVisibleDecl(*LastI);
if (D)
R.addDecl(D);
Modified: cfe/trunk/test/Sema/function.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/function.c?rev=148154&r1=148153&r2=148154&view=diff
==============================================================================
--- cfe/trunk/test/Sema/function.c (original)
+++ cfe/trunk/test/Sema/function.c Fri Jan 13 17:06:53 2012
@@ -89,3 +89,6 @@
// missing ',' before '...'
void t20(int i...) { } // expected-error {{requires a comma}}
+
+int n;
+void t21(int n, int (*array)[n]);
More information about the cfe-commits
mailing list