]> granicus.if.org Git - clang/commitdiff
When looking for an entity's Scope, don't consider scopes that can't contain declarat...
authorSebastian Redl <sebastian.redl@getdesigned.at>
Thu, 8 Jul 2010 23:07:34 +0000 (23:07 +0000)
committerSebastian Redl <sebastian.redl@getdesigned.at>
Thu, 8 Jul 2010 23:07:34 +0000 (23:07 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@107927 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/Sema.cpp
test/SemaCXX/implicit-member-functions.cpp

index 6194c293d2ba2092143040a037843a0949f82f78..cddc84eeedff6ed5c3c5e1078e9f5ff9850421ad 100644 (file)
@@ -405,9 +405,12 @@ Scope *Sema::getScopeForContext(DeclContext *Ctx) {
   
   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;
index 79cc3679f4981bf44b1805412fbb3d1f5f1ad904..5333094d53bd4c09b4d0202d3ba1ab289d7e06ed 100644 (file)
@@ -39,3 +39,14 @@ namespace PR6570 {
   };
 
 }
+
+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();
+}