]> granicus.if.org Git - clang/commitdiff
Combine instantiation context of field initializer with context of class.
authorSerge Pavlov <sepavloff@gmail.com>
Tue, 28 Apr 2015 17:58:47 +0000 (17:58 +0000)
committerSerge Pavlov <sepavloff@gmail.com>
Tue, 28 Apr 2015 17:58:47 +0000 (17:58 +0000)
Inclass initializer is instantiated in its own LocalInstantiationScope. It
causes problems when instantiating local classes - when instantiation scope
is searched for DeclContext of the field, the search fails. As a solution,
the instantiation scope of field initializer is combined with its outer
scope.

This patch fixes PR23194.

Differential Revision: http://reviews.llvm.org/D9258

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@236005 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaTemplateInstantiate.cpp
test/SemaTemplate/instantiate-local-class.cpp

index eec13c581d4088d0bdd6005e300b41d6fd60de33..62b506276e6e03c2f2d441ab7f81d165329205c6 100644 (file)
@@ -2233,7 +2233,7 @@ bool Sema::InstantiateInClassInitializer(
   EnterExpressionEvaluationContext EvalContext(*this,
                                                Sema::PotentiallyEvaluated);
 
-  LocalInstantiationScope Scope(*this);
+  LocalInstantiationScope Scope(*this, true);
 
   // Instantiate the initializer.
   ActOnStartCXXInClassMemberInitializer();
index c9897b9c614b9e8584aa18ea13bf41ac5ebf0f50..367134a2a5311bc07040b0bf8a022a0f88faf2b1 100644 (file)
@@ -194,3 +194,22 @@ struct B {
   void f() { F<int>(); }
 };
 }
+
+namespace PR23194 {
+  struct X {
+    int operator()() const { return 0; }
+  };
+  struct Y {
+    Y(int) {}
+  };
+  template <bool = true> int make_seed_pair() noexcept {
+    struct state_t {
+      X x;
+      Y y{x()};
+    };
+    return 0;
+  }
+  int func() {
+    return make_seed_pair();
+  }
+}