[cfe-commits] r99377 - in /cfe/trunk: lib/Sema/SemaTemplateInstantiate.cpp test/SemaTemplate/instantiate-function-params.cpp

Douglas Gregor dgregor at apple.com
Tue Mar 23 18:33:17 PDT 2010


Author: dgregor
Date: Tue Mar 23 20:33:17 2010
New Revision: 99377

URL: http://llvm.org/viewvc/llvm-project?rev=99377&view=rev
Log:
Each non-local class instantiation is its own local instantiation
scope. Fixes PR6619.

Added:
    cfe/trunk/test/SemaTemplate/instantiate-function-params.cpp   (with props)
Modified:
    cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp

Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp?rev=99377&r1=99376&r2=99377&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp Tue Mar 23 20:33:17 2010
@@ -1159,6 +1159,12 @@
   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();
 

Added: cfe/trunk/test/SemaTemplate/instantiate-function-params.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/instantiate-function-params.cpp?rev=99377&view=auto
==============================================================================
--- cfe/trunk/test/SemaTemplate/instantiate-function-params.cpp (added)
+++ cfe/trunk/test/SemaTemplate/instantiate-function-params.cpp Tue Mar 23 20:33:17 2010
@@ -0,0 +1,33 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+// PR6619
+template<bool C> struct if_c { };
+template<typename T1> struct if_ {
+  typedef if_c< static_cast<bool>(T1::value)> almost_type_; // expected-note 7{{in instantiation}}
+};
+template <class Model, void (Model::*)()> struct wrap_constraints { };
+template <class Model> 
+inline char has_constraints_(Model* ,  // expected-note 4{{while substituting}} \
+                             // expected-note 3{{candidate template ignored}}
+                               wrap_constraints<Model,&Model::constraints>* = 0); // expected-note 4{{in instantiation}}
+
+template <class Model> struct not_satisfied {
+  static const bool value = sizeof( has_constraints_((Model*)0)  == 1); // expected-error 3{{no matching function}}
+};
+template <class ModelFn> struct requirement_;
+template <void(*)()> struct instantiate {
+};
+template <class Model> struct requirement_<void(*)(Model)>                           : if_<       not_satisfied<Model>         >::type { // expected-error 3{{no type named}} \
+  // expected-note 7{{in instantiation}}
+};
+template <class Model> struct usage_requirements {
+};
+template < typename TT > struct InputIterator                            {
+    typedef  instantiate< & requirement_<void(*)(usage_requirements<InputIterator> x)>::failed> boost_concept_check1; // expected-note 2{{in instantiation}}
+};
+template < typename TT > struct ForwardIterator                              : InputIterator<TT>                              { // expected-note 2{{in instantiation}}
+  typedef instantiate< & requirement_<void(*)(usage_requirements<ForwardIterator> x)>::failed> boost_concept_check2; // expected-note 2 {{in instantiation}}
+
+};
+typedef instantiate< &requirement_<void(*)(ForwardIterator<char*> x)>::failed> boost_concept_checkX; // expected-error{{no member named}} \
+// expected-note 6{{in instantiation}}

Propchange: cfe/trunk/test/SemaTemplate/instantiate-function-params.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cfe/trunk/test/SemaTemplate/instantiate-function-params.cpp
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cfe/trunk/test/SemaTemplate/instantiate-function-params.cpp
------------------------------------------------------------------------------
    svn:mime-type = text/plain





More information about the cfe-commits mailing list