aboutsummaryrefslogtreecommitdiff
path: root/lib/Sema/SemaDecl.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2011-03-14 21:19:51 +0000
committerDouglas Gregor <dgregor@apple.com>2011-03-14 21:19:51 +0000
commit7cbc558ffda5877ec4d2e432534e3d3d4ac10050 (patch)
treeda94f5bf295b07b01b82017c6f96caf478ddb6f0 /lib/Sema/SemaDecl.cpp
parentdc0f137295bc7ec5b231ff1842388f149f43c0c8 (diff)
When synthesizing a label declaration based on a goto statement that
cannot yet be resolved, be sure to push the new label declaration into the right place within the identifier chain. Otherwise, name lookup in C++ gets confused when searching for names that are lexically closer than the label. Fixes PR9463. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@127623 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaDecl.cpp')
-rw-r--r--lib/Sema/SemaDecl.cpp15
1 files changed, 14 insertions, 1 deletions
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index 7c3f726a99..19d96f2ec0 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -494,7 +494,20 @@ void Sema::PushOnScopeChains(NamedDecl *D, Scope *S, bool AddToContext) {
}
S->AddDecl(D);
- IdResolver.AddDecl(D);
+
+ if (isa<LabelDecl>(D) && !cast<LabelDecl>(D)->isGnuLocal()) {
+ // Implicitly-generated labels may end up getting generated in an order that
+ // isn't strictly lexical, which breaks name lookup. Be careful to insert
+ // the label at the appropriate place in the identifier chain.
+ for (I = IdResolver.begin(D->getDeclName()); I != IEnd; ++I) {
+ if ((*I)->getLexicalDeclContext()->Encloses(CurContext))
+ break;
+ }
+
+ IdResolver.InsertDecl(I, D);
+ } else {
+ IdResolver.AddDecl(D);
+ }
}
bool Sema::isDeclInScope(NamedDecl *&D, DeclContext *Ctx, Scope *S,