From: Douglas Gregor Date: Wed, 12 May 2010 17:27:19 +0000 (+0000) Subject: Whenever we instantiate a function definition or class, enter a new X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9679cafc6368cceed1a5e69d3038d0316401b352;p=clang Whenever we instantiate a function definition or class, enter a new potentially-evaluated expression context, to ensure that used declarations get properly marked. Fixes PR7123. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@103624 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaTemplateInstantiate.cpp b/lib/Sema/SemaTemplateInstantiate.cpp index 06b953931f..589b995653 100644 --- a/lib/Sema/SemaTemplateInstantiate.cpp +++ b/lib/Sema/SemaTemplateInstantiate.cpp @@ -1175,6 +1175,8 @@ Sema::InstantiateClass(SourceLocation PointOfInstantiation, // Enter the scope of this instantiation. We don't use // PushDeclContext because we don't have a scope. ContextRAII SavedContext(*this, Instantiation); + EnterExpressionEvaluationContext EvalContext(*this, + Action::PotentiallyEvaluated); // If this is an instantiation of a local class, merge this local // instantiation scope with the enclosing scope. Otherwise, every diff --git a/lib/Sema/SemaTemplateInstantiateDecl.cpp b/lib/Sema/SemaTemplateInstantiateDecl.cpp index d3d6c2209f..adba32ecec 100644 --- a/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -2011,6 +2011,8 @@ void Sema::InstantiateFunctionDefinition(SourceLocation PointOfInstantiation, if (Recursive) PendingImplicitInstantiations.swap(SavedPendingImplicitInstantiations); + EnterExpressionEvaluationContext EvalContext(*this, + Action::PotentiallyEvaluated); ActOnStartOfFunctionDef(0, DeclPtrTy::make(Function)); // Introduce a new scope where local variable instantiations will be diff --git a/test/SemaTemplate/instantiate-field.cpp b/test/SemaTemplate/instantiate-field.cpp index 60d4b21cac..a260635778 100644 --- a/test/SemaTemplate/instantiate-field.cpp +++ b/test/SemaTemplate/instantiate-field.cpp @@ -26,3 +26,58 @@ void test2(const X *xf) { void test3(const X *xf) { (void)xf->x; // expected-note{{in instantiation of template class 'X' requested here}} } + +namespace PR7123 { + template struct requirement_; + + template struct instantiate + { }; + + template struct requirement ; + struct failed ; + + template struct requirement + { + static void failed() + { + ((Model*)0)->~Model(); // expected-note{{in instantiation of}} + } + }; + + template struct requirement_ : requirement + { }; + + template struct Requires_ + { typedef void type; }; + + template struct usage_requirements + { + ~usage_requirements() + {((Model*)0)->~Model(); } // expected-note{{in instantiation of}} + }; + + template < typename TT > struct BidirectionalIterator + { + enum + { value = 0 }; + + instantiate< requirement_)>::failed> int534; // expected-note{{in instantiation of}} + + ~BidirectionalIterator() + { i--; } // expected-error{{cannot decrement value of type 'PR7123::X'}} + + TT i; + }; + + struct X + { }; + + template + typename Requires_< BidirectionalIterator::value >::type sort(RanIter,RanIter){} + + void f() + { + X x; + sort(x,x); + } +}