[cfe-commits] r107927 - in /cfe/trunk: lib/Sema/Sema.cpp test/SemaCXX/implicit-member-functions.cpp
Sebastian Redl
sebastian.redl at getdesigned.at
Thu Jul 8 16:07:34 PDT 2010
Author: cornedbee
Date: Thu Jul 8 18:07:34 2010
New Revision: 107927
URL: http://llvm.org/viewvc/llvm-project?rev=107927&view=rev
Log:
When looking for an entity's Scope, don't consider scopes that can't contain declarations. Fixes PR7594.
Modified:
cfe/trunk/lib/Sema/Sema.cpp
cfe/trunk/test/SemaCXX/implicit-member-functions.cpp
Modified: cfe/trunk/lib/Sema/Sema.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.cpp?rev=107927&r1=107926&r2=107927&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/Sema.cpp (original)
+++ cfe/trunk/lib/Sema/Sema.cpp Thu Jul 8 18:07:34 2010
@@ -405,9 +405,12 @@
Ctx = Ctx->getPrimaryContext();
for (Scope *S = getCurScope(); S; S = S->getParent()) {
- if (DeclContext *Entity = static_cast<DeclContext *> (S->getEntity()))
- if (Ctx == Entity->getPrimaryContext())
- return S;
+ // Ignore scopes that cannot have declarations. This is important for
+ // out-of-line definitions of static class members.
+ if (S->getFlags() & (Scope::DeclScope | Scope::TemplateParamScope))
+ if (DeclContext *Entity = static_cast<DeclContext *> (S->getEntity()))
+ if (Ctx == Entity->getPrimaryContext())
+ return S;
}
return 0;
Modified: cfe/trunk/test/SemaCXX/implicit-member-functions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/implicit-member-functions.cpp?rev=107927&r1=107926&r2=107927&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/implicit-member-functions.cpp (original)
+++ cfe/trunk/test/SemaCXX/implicit-member-functions.cpp Thu Jul 8 18:07:34 2010
@@ -39,3 +39,14 @@
};
}
+
+namespace PR7594 {
+ // If the lazy declaration of special member functions is triggered
+ // in an out-of-line initializer, make sure the functions aren't in
+ // the initializer scope. This used to crash Clang:
+ struct C {
+ C();
+ static C *c;
+ };
+ C *C::c = new C();
+}
More information about the cfe-commits
mailing list