From: Douglas Gregor Date: Wed, 24 Mar 2010 01:33:17 +0000 (+0000) Subject: Each non-local class instantiation is its own local instantiation X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=05030bb6790b259a169b25665656db2aee30ccda;p=clang Each non-local class instantiation is its own local instantiation scope. Fixes PR6619. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@99377 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaTemplateInstantiate.cpp b/lib/Sema/SemaTemplateInstantiate.cpp index 0d6acd0e81..ac1bf7219c 100644 --- a/lib/Sema/SemaTemplateInstantiate.cpp +++ b/lib/Sema/SemaTemplateInstantiate.cpp @@ -1159,6 +1159,12 @@ Sema::InstantiateClass(SourceLocation PointOfInstantiation, DeclContext *PreviousContext = CurContext; CurContext = Instantiation; + // If this is an instantiation of a local class, merge this local + // instantiation scope with the enclosing scope. Otherwise, every + // instantiation of a class has its own local instantiation scope. + bool MergeWithParentScope = !Instantiation->isDefinedOutsideFunctionOrMethod(); + Sema::LocalInstantiationScope Scope(*this, MergeWithParentScope); + // Start the definition of this instantiation. Instantiation->startDefinition(); diff --git a/test/SemaTemplate/instantiate-function-params.cpp b/test/SemaTemplate/instantiate-function-params.cpp new file mode 100644 index 0000000000..a574dbb787 --- /dev/null +++ b/test/SemaTemplate/instantiate-function-params.cpp @@ -0,0 +1,33 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +// PR6619 +template struct if_c { }; +template struct if_ { + typedef if_c< static_cast(T1::value)> almost_type_; // expected-note 7{{in instantiation}} +}; +template struct wrap_constraints { }; +template +inline char has_constraints_(Model* , // expected-note 4{{while substituting}} \ + // expected-note 3{{candidate template ignored}} + wrap_constraints* = 0); // expected-note 4{{in instantiation}} + +template struct not_satisfied { + static const bool value = sizeof( has_constraints_((Model*)0) == 1); // expected-error 3{{no matching function}} +}; +template struct requirement_; +template struct instantiate { +}; +template struct requirement_ : if_< not_satisfied >::type { // expected-error 3{{no type named}} \ + // expected-note 7{{in instantiation}} +}; +template struct usage_requirements { +}; +template < typename TT > struct InputIterator { + typedef instantiate< & requirement_ x)>::failed> boost_concept_check1; // expected-note 2{{in instantiation}} +}; +template < typename TT > struct ForwardIterator : InputIterator { // expected-note 2{{in instantiation}} + typedef instantiate< & requirement_ x)>::failed> boost_concept_check2; // expected-note 2 {{in instantiation}} + +}; +typedef instantiate< &requirement_ x)>::failed> boost_concept_checkX; // expected-error{{no member named}} \ +// expected-note 6{{in instantiation}}