[llvm-branch-commits] [cfe-branch] r282636 - Merging rr280190:

Eric Fiselier via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Wed Sep 28 14:25:06 PDT 2016


Author: ericwf
Date: Wed Sep 28 16:25:06 2016
New Revision: 282636

URL: http://llvm.org/viewvc/llvm-project?rev=282636&view=rev
Log:
Merging rr280190:
------------------------------------------------------------------------
r280190 | rsmith | 2016-08-30 20:15:21 -0600 (Tue, 30 Aug 2016) | 12 lines

PR12298 et al: don't recursively instantiate a template specialization from
within the instantiation of that same specialization. This could previously
happen for eagerly-instantiated function templates, variable templates,
exception specifications, default arguments, and a handful of other cases.

We still have an issue here for default template arguments that recursively
make use of themselves and likewise for substitution into the type of a
non-type template parameter, but in those cases we're producing a different
entity each time, so they should instead be caught by the instantiation depth
limit. However, currently we will typically run out of stack before we reach
it. :(

------------------------------------------------------------------------

Modified:
    cfe/branches/release_39/include/clang/AST/DeclTemplate.h
    cfe/branches/release_39/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/branches/release_39/include/clang/Sema/Sema.h
    cfe/branches/release_39/lib/Sema/SemaDecl.cpp
    cfe/branches/release_39/lib/Sema/SemaExpr.cpp
    cfe/branches/release_39/lib/Sema/SemaTemplate.cpp
    cfe/branches/release_39/lib/Sema/SemaTemplateInstantiate.cpp
    cfe/branches/release_39/lib/Sema/SemaTemplateInstantiateDecl.cpp
    cfe/branches/release_39/test/SemaTemplate/instantiate-self.cpp
    cfe/branches/release_39/test/SemaTemplate/instantiation-depth-exception-spec.cpp
    cfe/branches/release_39/test/SemaTemplate/instantiation-depth.cpp

Modified: cfe/branches/release_39/include/clang/AST/DeclTemplate.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_39/include/clang/AST/DeclTemplate.h?rev=282636&r1=282635&r2=282636&view=diff
==============================================================================
--- cfe/branches/release_39/include/clang/AST/DeclTemplate.h (original)
+++ cfe/branches/release_39/include/clang/AST/DeclTemplate.h Wed Sep 28 16:25:06 2016
@@ -44,6 +44,8 @@ class VarTemplatePartialSpecializationDe
 typedef llvm::PointerUnion3<TemplateTypeParmDecl*, NonTypeTemplateParmDecl*,
                             TemplateTemplateParmDecl*> TemplateParameter;
 
+NamedDecl *getAsNamedDecl(TemplateParameter P);
+
 /// \brief Stores a list of template parameters for a TemplateDecl and its
 /// derived classes.
 class TemplateParameterList final
@@ -2912,6 +2914,14 @@ public:
   friend class ASTDeclWriter;
 };
 
+inline NamedDecl *getAsNamedDecl(TemplateParameter P) {
+  if (auto *PD = P.dyn_cast<TemplateTypeParmDecl*>())
+    return PD;
+  if (auto *PD = P.dyn_cast<NonTypeTemplateParmDecl*>())
+    return PD;
+  return P.get<TemplateTemplateParmDecl*>();
+}
+
 } /* end of namespace clang */
 
 #endif

Modified: cfe/branches/release_39/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_39/include/clang/Basic/DiagnosticSemaKinds.td?rev=282636&r1=282635&r2=282636&view=diff
==============================================================================
--- cfe/branches/release_39/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/branches/release_39/include/clang/Basic/DiagnosticSemaKinds.td Wed Sep 28 16:25:06 2016
@@ -6917,6 +6917,10 @@ def err_in_class_initializer_not_yet_par
 def err_in_class_initializer_not_yet_parsed_outer_class
     : Error<"cannot use defaulted default constructor of %0 within "
             "%1 outside of member functions because %2 has an initializer">;
+def err_in_class_initializer_cycle
+    : Error<"default member initializer for %0 uses itself">;
+def err_exception_spec_cycle
+    : Error<"exception specification of %0 uses itself">;
 
 def ext_in_class_initializer_non_constant : Extension<
   "in-class initializer for static data member is not a constant expression; "

Modified: cfe/branches/release_39/include/clang/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_39/include/clang/Sema/Sema.h?rev=282636&r1=282635&r2=282636&view=diff
==============================================================================
--- cfe/branches/release_39/include/clang/Sema/Sema.h (original)
+++ cfe/branches/release_39/include/clang/Sema/Sema.h Wed Sep 28 16:25:06 2016
@@ -18,6 +18,7 @@
 #include "clang/AST/Attr.h"
 #include "clang/AST/Availability.h"
 #include "clang/AST/DeclarationName.h"
+#include "clang/AST/DeclTemplate.h"
 #include "clang/AST/Expr.h"
 #include "clang/AST/ExprObjC.h"
 #include "clang/AST/ExternalASTSource.h"
@@ -6613,10 +6614,10 @@ public:
       TemplateInstantiation,
 
       /// We are instantiating a default argument for a template
-      /// parameter. The Entity is the template, and
-      /// TemplateArgs/NumTemplateArguments provides the template
-      /// arguments as specified.
-      /// FIXME: Use a TemplateArgumentList
+      /// parameter. The Entity is the template parameter whose argument is
+      /// being instantiated, the Template is the template, and the
+      /// TemplateArgs/NumTemplateArguments provide the template arguments as
+      /// specified.
       DefaultTemplateArgumentInstantiation,
 
       /// We are instantiating a default argument for a function.
@@ -6731,6 +6732,9 @@ public:
   SmallVector<ActiveTemplateInstantiation, 16>
     ActiveTemplateInstantiations;
 
+  /// Specializations whose definitions are currently being instantiated.
+  llvm::DenseSet<std::pair<Decl *, unsigned>> InstantiatingSpecializations;
+
   /// \brief Extra modules inspected when performing a lookup during a template
   /// instantiation. Computed lazily.
   SmallVector<Module*, 16> ActiveTemplateInstantiationLookupModules;
@@ -6837,12 +6841,12 @@ public:
     /// \brief Note that we are instantiating a default argument in a
     /// template-id.
     InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
-                          TemplateDecl *Template,
+                          TemplateParameter Param, TemplateDecl *Template,
                           ArrayRef<TemplateArgument> TemplateArgs,
                           SourceRange InstantiationRange = SourceRange());
 
-    /// \brief Note that we are instantiating a default argument in a
-    /// template-id.
+    /// \brief Note that we are substituting either explicitly-specified or
+    /// deduced template arguments during function template argument deduction.
     InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
                           FunctionTemplateDecl *FunctionTemplate,
                           ArrayRef<TemplateArgument> TemplateArgs,
@@ -6909,9 +6913,14 @@ public:
     /// recursive template instantiations.
     bool isInvalid() const { return Invalid; }
 
+    /// \brief Determine whether we are already instantiating this
+    /// specialization in some surrounding active instantiation.
+    bool isAlreadyInstantiating() const { return AlreadyInstantiating; }
+
   private:
     Sema &SemaRef;
     bool Invalid;
+    bool AlreadyInstantiating;
     bool SavedInNonInstantiationSFINAEContext;
     bool CheckInstantiationDepth(SourceLocation PointOfInstantiation,
                                  SourceRange InstantiationRange);

Modified: cfe/branches/release_39/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_39/lib/Sema/SemaDecl.cpp?rev=282636&r1=282635&r2=282636&view=diff
==============================================================================
--- cfe/branches/release_39/lib/Sema/SemaDecl.cpp (original)
+++ cfe/branches/release_39/lib/Sema/SemaDecl.cpp Wed Sep 28 16:25:06 2016
@@ -9615,7 +9615,8 @@ void Sema::AddInitializerToDecl(Decl *Re
   }
 
   VarDecl *Def;
-  if ((Def = VDecl->getDefinition()) && Def != VDecl) {
+  if ((Def = VDecl->getDefinition()) && Def != VDecl &&
+      (!VDecl->isStaticDataMember() || VDecl->isOutOfLine())) {
     NamedDecl *Hidden = nullptr;
     if (!hasVisibleDefinition(Def, &Hidden) &&
         (VDecl->getFormalLinkage() == InternalLinkage ||

Modified: cfe/branches/release_39/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_39/lib/Sema/SemaExpr.cpp?rev=282636&r1=282635&r2=282636&view=diff
==============================================================================
--- cfe/branches/release_39/lib/Sema/SemaExpr.cpp (original)
+++ cfe/branches/release_39/lib/Sema/SemaExpr.cpp Wed Sep 28 16:25:06 2016
@@ -4522,6 +4522,11 @@ ExprResult Sema::BuildCXXDefaultArgExpr(
                                MutiLevelArgList.getInnermost());
     if (Inst.isInvalid())
       return ExprError();
+    if (Inst.isAlreadyInstantiating()) {
+      Diag(Param->getLocStart(), diag::err_recursive_default_argument) << FD;
+      Param->setInvalidDecl();
+      return ExprError();
+    }
 
     ExprResult Result;
     {

Modified: cfe/branches/release_39/lib/Sema/SemaTemplate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_39/lib/Sema/SemaTemplate.cpp?rev=282636&r1=282635&r2=282636&view=diff
==============================================================================
--- cfe/branches/release_39/lib/Sema/SemaTemplate.cpp (original)
+++ cfe/branches/release_39/lib/Sema/SemaTemplate.cpp Wed Sep 28 16:25:06 2016
@@ -3256,7 +3256,7 @@ SubstDefaultTemplateArgument(Sema &SemaR
   // on the previously-computed template arguments.
   if (ArgType->getType()->isDependentType()) {
     Sema::InstantiatingTemplate Inst(SemaRef, TemplateLoc,
-                                     Template, Converted,
+                                     Param, Template, Converted,
                                      SourceRange(TemplateLoc, RAngleLoc));
     if (Inst.isInvalid())
       return nullptr;
@@ -3308,7 +3308,7 @@ SubstDefaultTemplateArgument(Sema &SemaR
                              NonTypeTemplateParmDecl *Param,
                         SmallVectorImpl<TemplateArgument> &Converted) {
   Sema::InstantiatingTemplate Inst(SemaRef, TemplateLoc,
-                                   Template, Converted,
+                                   Param, Template, Converted,
                                    SourceRange(TemplateLoc, RAngleLoc));
   if (Inst.isInvalid())
     return ExprError();
@@ -3359,8 +3359,9 @@ SubstDefaultTemplateArgument(Sema &SemaR
                              TemplateTemplateParmDecl *Param,
                        SmallVectorImpl<TemplateArgument> &Converted,
                              NestedNameSpecifierLoc &QualifierLoc) {
-  Sema::InstantiatingTemplate Inst(SemaRef, TemplateLoc, Template, Converted,
-                                   SourceRange(TemplateLoc, RAngleLoc));
+  Sema::InstantiatingTemplate Inst(
+      SemaRef, TemplateLoc, TemplateParameter(Param), Template, Converted,
+      SourceRange(TemplateLoc, RAngleLoc));
   if (Inst.isInvalid())
     return TemplateName();
 
@@ -3981,7 +3982,9 @@ bool Sema::CheckTemplateArgumentList(Tem
     }
 
     // Introduce an instantiation record that describes where we are using
-    // the default template argument.
+    // the default template argument. We're not actually instantiating a
+    // template here, we just create this object to put a note into the
+    // context stack.
     InstantiatingTemplate Inst(*this, RAngleLoc, Template, *Param, Converted,
                                SourceRange(TemplateLoc, RAngleLoc));
     if (Inst.isInvalid())

Modified: cfe/branches/release_39/lib/Sema/SemaTemplateInstantiate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_39/lib/Sema/SemaTemplateInstantiate.cpp?rev=282636&r1=282635&r2=282636&view=diff
==============================================================================
--- cfe/branches/release_39/lib/Sema/SemaTemplateInstantiate.cpp (original)
+++ cfe/branches/release_39/lib/Sema/SemaTemplateInstantiate.cpp Wed Sep 28 16:25:06 2016
@@ -225,6 +225,10 @@ Sema::InstantiatingTemplate::Instantiati
     Inst.NumTemplateArgs = TemplateArgs.size();
     Inst.DeductionInfo = DeductionInfo;
     Inst.InstantiationRange = InstantiationRange;
+    AlreadyInstantiating =
+        !SemaRef.InstantiatingSpecializations
+             .insert(std::make_pair(Inst.Entity->getCanonicalDecl(), Inst.Kind))
+             .second;
     SemaRef.InNonInstantiationSFINAEContext = false;
     SemaRef.ActiveTemplateInstantiations.push_back(Inst);
     if (!Inst.isInstantiationRecord())
@@ -247,13 +251,14 @@ Sema::InstantiatingTemplate::Instantiati
           PointOfInstantiation, InstantiationRange, Entity) {}
 
 Sema::InstantiatingTemplate::InstantiatingTemplate(
-    Sema &SemaRef, SourceLocation PointOfInstantiation, TemplateDecl *Template,
-    ArrayRef<TemplateArgument> TemplateArgs, SourceRange InstantiationRange)
+    Sema &SemaRef, SourceLocation PointOfInstantiation, TemplateParameter Param,
+    TemplateDecl *Template, ArrayRef<TemplateArgument> TemplateArgs,
+    SourceRange InstantiationRange)
     : InstantiatingTemplate(
           SemaRef,
           ActiveTemplateInstantiation::DefaultTemplateArgumentInstantiation,
-          PointOfInstantiation, InstantiationRange, Template, nullptr,
-          TemplateArgs) {}
+          PointOfInstantiation, InstantiationRange, getAsNamedDecl(Param),
+          Template, TemplateArgs) {}
 
 Sema::InstantiatingTemplate::InstantiatingTemplate(
     Sema &SemaRef, SourceLocation PointOfInstantiation,
@@ -263,7 +268,11 @@ Sema::InstantiatingTemplate::Instantiati
     sema::TemplateDeductionInfo &DeductionInfo, SourceRange InstantiationRange)
     : InstantiatingTemplate(SemaRef, Kind, PointOfInstantiation,
                             InstantiationRange, FunctionTemplate, nullptr,
-                            TemplateArgs, &DeductionInfo) {}
+                            TemplateArgs, &DeductionInfo) {
+  assert(
+    Kind == ActiveTemplateInstantiation::ExplicitTemplateArgumentSubstitution ||
+    Kind == ActiveTemplateInstantiation::DeducedTemplateArgumentSubstitution);
+}
 
 Sema::InstantiatingTemplate::InstantiatingTemplate(
     Sema &SemaRef, SourceLocation PointOfInstantiation,
@@ -327,7 +336,8 @@ Sema::InstantiatingTemplate::Instantiati
 
 void Sema::InstantiatingTemplate::Clear() {
   if (!Invalid) {
-    if (!SemaRef.ActiveTemplateInstantiations.back().isInstantiationRecord()) {
+    auto &Active = SemaRef.ActiveTemplateInstantiations.back();
+    if (!Active.isInstantiationRecord()) {
       assert(SemaRef.NonInstantiationEntries > 0);
       --SemaRef.NonInstantiationEntries;
     }
@@ -345,6 +355,10 @@ void Sema::InstantiatingTemplate::Clear(
       SemaRef.ActiveTemplateInstantiationLookupModules.pop_back();
     }
 
+    if (!AlreadyInstantiating)
+      SemaRef.InstantiatingSpecializations.erase(
+          std::make_pair(Active.Entity, Active.Kind));
+
     SemaRef.ActiveTemplateInstantiations.pop_back();
     Invalid = true;
   }
@@ -443,7 +457,7 @@ void Sema::PrintInstantiationStack() {
     }
 
     case ActiveTemplateInstantiation::DefaultTemplateArgumentInstantiation: {
-      TemplateDecl *Template = cast<TemplateDecl>(Active->Entity);
+      TemplateDecl *Template = cast<TemplateDecl>(Active->Template);
       SmallVector<char, 128> TemplateArgsStr;
       llvm::raw_svector_ostream OS(TemplateArgsStr);
       Template->printName(OS);
@@ -1950,6 +1964,7 @@ Sema::InstantiateClass(SourceLocation Po
   InstantiatingTemplate Inst(*this, PointOfInstantiation, Instantiation);
   if (Inst.isInvalid())
     return true;
+  assert(!Inst.isAlreadyInstantiating() && "should have been caught by caller");
   PrettyDeclStackTraceEntry CrashInfo(*this, Instantiation, SourceLocation(),
                                       "instantiating class definition");
 
@@ -2175,6 +2190,8 @@ bool Sema::InstantiateEnum(SourceLocatio
   InstantiatingTemplate Inst(*this, PointOfInstantiation, Instantiation);
   if (Inst.isInvalid())
     return true;
+  if (Inst.isAlreadyInstantiating())
+    return false;
   PrettyDeclStackTraceEntry CrashInfo(*this, Instantiation, SourceLocation(),
                                       "instantiating enum definition");
 
@@ -2249,6 +2266,12 @@ bool Sema::InstantiateInClassInitializer
   InstantiatingTemplate Inst(*this, PointOfInstantiation, Instantiation);
   if (Inst.isInvalid())
     return true;
+  if (Inst.isAlreadyInstantiating()) {
+    // Error out if we hit an instantiation cycle for this initializer.
+    Diag(PointOfInstantiation, diag::err_in_class_initializer_cycle)
+      << Instantiation;
+    return true;
+  }
   PrettyDeclStackTraceEntry CrashInfo(*this, Instantiation, SourceLocation(),
                                       "instantiating default member init");
 

Modified: cfe/branches/release_39/lib/Sema/SemaTemplateInstantiateDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_39/lib/Sema/SemaTemplateInstantiateDecl.cpp?rev=282636&r1=282635&r2=282636&view=diff
==============================================================================
--- cfe/branches/release_39/lib/Sema/SemaTemplateInstantiateDecl.cpp (original)
+++ cfe/branches/release_39/lib/Sema/SemaTemplateInstantiateDecl.cpp Wed Sep 28 16:25:06 2016
@@ -3360,6 +3360,13 @@ void Sema::InstantiateExceptionSpec(Sour
     UpdateExceptionSpec(Decl, EST_None);
     return;
   }
+  if (Inst.isAlreadyInstantiating()) {
+    // This exception specification indirectly depends on itself. Reject.
+    // FIXME: Corresponding rule in the standard?
+    Diag(PointOfInstantiation, diag::err_exception_spec_cycle) << Decl;
+    UpdateExceptionSpec(Decl, EST_None);
+    return;
+  }
 
   // Enter the scope of this instantiation. We don't use
   // PushDeclContext because we don't have a scope.
@@ -3619,7 +3626,7 @@ void Sema::InstantiateFunctionDefinition
   }
 
   InstantiatingTemplate Inst(*this, PointOfInstantiation, Function);
-  if (Inst.isInvalid())
+  if (Inst.isInvalid() || Inst.isAlreadyInstantiating())
     return;
   PrettyDeclStackTraceEntry CrashInfo(*this, Function, SourceLocation(),
                                       "instantiating function definition");
@@ -3882,10 +3889,6 @@ void Sema::InstantiateVariableInitialize
   else if (OldVar->isInline())
     Var->setImplicitlyInline();
 
-  if (Var->getAnyInitializer())
-    // We already have an initializer in the class.
-    return;
-
   if (OldVar->getInit()) {
     if (Var->isStaticDataMember() && !OldVar->isOutOfLine())
       PushExpressionEvaluationContext(Sema::ConstantEvaluated, OldVar);
@@ -3921,9 +3924,23 @@ void Sema::InstantiateVariableInitialize
     }
 
     PopExpressionEvaluationContext();
-  } else if ((!Var->isStaticDataMember() || Var->isOutOfLine()) &&
-             !Var->isCXXForRangeDecl())
+  } else {
+    if (Var->isStaticDataMember()) {
+      if (!Var->isOutOfLine())
+        return;
+
+      // If the declaration inside the class had an initializer, don't add
+      // another one to the out-of-line definition.
+      if (OldVar->getFirstDecl()->hasInit())
+        return;
+    }
+
+    // We'll add an initializer to a for-range declaration later.
+    if (Var->isCXXForRangeDecl())
+      return;
+
     ActOnUninitializedDecl(Var, false);
+  }
 }
 
 /// \brief Instantiate the definition of the given variable from its
@@ -4013,7 +4030,7 @@ void Sema::InstantiateVariableDefinition
       // FIXME: Factor out the duplicated instantiation context setup/tear down
       // code here.
       InstantiatingTemplate Inst(*this, PointOfInstantiation, Var);
-      if (Inst.isInvalid())
+      if (Inst.isInvalid() || Inst.isAlreadyInstantiating())
         return;
       PrettyDeclStackTraceEntry CrashInfo(*this, Var, SourceLocation(),
                                           "instantiating variable initializer");
@@ -4142,7 +4159,7 @@ void Sema::InstantiateVariableDefinition
   }
 
   InstantiatingTemplate Inst(*this, PointOfInstantiation, Var);
-  if (Inst.isInvalid())
+  if (Inst.isInvalid() || Inst.isAlreadyInstantiating())
     return;
   PrettyDeclStackTraceEntry CrashInfo(*this, Var, SourceLocation(),
                                       "instantiating variable definition");

Modified: cfe/branches/release_39/test/SemaTemplate/instantiate-self.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_39/test/SemaTemplate/instantiate-self.cpp?rev=282636&r1=282635&r2=282636&view=diff
==============================================================================
--- cfe/branches/release_39/test/SemaTemplate/instantiate-self.cpp (original)
+++ cfe/branches/release_39/test/SemaTemplate/instantiate-self.cpp Wed Sep 28 16:25:06 2016
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -std=c++11 -verify %s
+// RUN: %clang_cc1 -std=c++1z -verify -pedantic-errors %s
 
 // Check that we deal with cases where the instantiation of a class template
 // recursively requires the instantiation of the same template.
@@ -47,9 +47,8 @@ namespace test4 {
   A<int> a; // expected-note {{in instantiation of}}
 }
 
-// FIXME: PR12298: Recursive constexpr function template instantiation leads to
+// PR12298: Recursive constexpr function template instantiation leads to
 // stack overflow.
-#if 0
 namespace test5 {
   template<typename T> struct A {
     constexpr T f(T k) { return g(k); }
@@ -57,22 +56,20 @@ namespace test5 {
       return k ? f(k-1)+1 : 0;
     }
   };
-  // This should be accepted.
-  constexpr int x = A<int>().f(5);
+  constexpr int x = A<int>().f(5); // ok
 }
 
 namespace test6 {
   template<typename T> constexpr T f(T);
   template<typename T> constexpr T g(T t) {
-    typedef int arr[f(T())];
+    typedef int arr[f(T())]; // expected-error {{variable length array}}
     return t;
   }
   template<typename T> constexpr T f(T t) {
-    typedef int arr[g(T())];
+    typedef int arr[g(T())]; // expected-error {{zero size array}} expected-note {{instantiation of}}
     return t;
   }
-  // This should be ill-formed.
-  int n = f(0);
+  int n = f(0); // expected-note 2{{instantiation of}}
 }
 
 namespace test7 {
@@ -80,10 +77,94 @@ namespace test7 {
     return t;
   }
   template<typename T> constexpr T f(T t) {
-    typedef int arr[g(T())];
+    typedef int arr[g(T() + 1)];
     return t;
   }
-  // This should be accepted.
   int n = f(0);
 }
+
+namespace test8 {
+  template<typename T> struct A {
+    int n = A{}.n; // expected-error {{default member initializer for 'n' uses itself}} expected-note {{instantiation of default member init}}
+  };
+  A<int> ai = {}; // expected-note {{instantiation of default member init}}
+}
+
+namespace test9 {
+  template<typename T> struct A { enum class B; };
+  // FIXME: It'd be nice to give the "it has not yet been instantiated" diagnostic here.
+  template<typename T> enum class A<T>::B { k = A<T>::B::k2, k2 = k }; // expected-error {{no member named 'k2'}}
+  auto k = A<int>::B::k; // expected-note {{in instantiation of}}
+}
+
+namespace test10 {
+  template<typename T> struct A {
+    void f() noexcept(noexcept(f())); // expected-error {{exception specification of 'f' uses itself}} expected-note {{instantiation of}}
+  };
+  bool b = noexcept(A<int>().f()); // expected-note {{instantiation of}}
+}
+
+namespace test11 {
+  template<typename T> const int var = var<T>;
+  int k = var<int>;
+
+  template<typename T> struct X {
+    static const int k = X<T>::k;
+  };
+  template<typename T> const int X<T>::k;
+  int q = X<int>::k;
+
+  template<typename T> struct Y {
+    static const int k;
+  };
+  template<typename T> const int Y<T>::k = Y<T>::k;
+  int r = Y<int>::k;
+}
+
+namespace test12 {
+  template<typename T> int f(T t, int = f(T())) {} // expected-error {{recursive evaluation of default argument}} expected-note {{instantiation of}}
+  struct X {};
+  int q = f(X()); // expected-note {{instantiation of}}
+}
+
+namespace test13 {
+  struct A {
+    // Cycle via type of non-type template parameter.
+    template<typename T, typename T::template W<T>::type U = 0> struct W { using type = int; };
+    // Cycle via default template argument.
+    template<typename T, typename U = typename T::template X<T>> struct X {};
+    template<typename T, int U = T::template Y<T>::value> struct Y { static const int value = 0; };
+    template<typename T, template<typename> typename U = T::template Z<T>::template nested> struct Z { template<typename> struct nested; };
+  };
+  template<typename T> struct Wrap {
+    template<typename U> struct W : A::W<T> {};
+    template<typename U> struct X : A::X<T> {};
+    template<typename U> struct Y : A::Y<T> {};
+    template<typename U> struct Z : A::Z<T> {};
+  };
+  struct B {
+    template<typename U> struct W { using type = int; };
+    template<typename U> struct X {};
+    template<typename U> struct Y { static const int value = 0; };
+    template<typename U> struct Z { template<typename> struct nested; };
+  };
+
+  A::W<B> awb;
+  A::X<B> axb;
+  A::Y<B> ayb;
+  A::Z<B> azb;
+
+  A::W<Wrap<Wrap<B>>> awwwb;
+  A::X<Wrap<Wrap<B>>> axwwb;
+  A::Y<Wrap<Wrap<B>>> aywwb;
+  A::Z<Wrap<Wrap<B>>> azwwb;
+
+  // FIXME: These tests cause us to use too much stack and crash on a self-hosted debug build.
+  // FIXME: Check for recursion here and give a better diagnostic.
+#if 0
+  A::W<A> awa;
+  A::X<A> axa;
+  A::Y<A> aya;
+  A::Z<A> aza;
 #endif
+}

Modified: cfe/branches/release_39/test/SemaTemplate/instantiation-depth-exception-spec.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_39/test/SemaTemplate/instantiation-depth-exception-spec.cpp?rev=282636&r1=282635&r2=282636&view=diff
==============================================================================
--- cfe/branches/release_39/test/SemaTemplate/instantiation-depth-exception-spec.cpp (original)
+++ cfe/branches/release_39/test/SemaTemplate/instantiation-depth-exception-spec.cpp Wed Sep 28 16:25:06 2016
@@ -1,11 +1,14 @@
 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 -ftemplate-depth 16 -fcxx-exceptions -fexceptions %s
 
-template<typename T> T go(T a) noexcept(noexcept(go(a))); // \
-// expected-error 16{{call to function 'go' that is neither visible}} \
-// expected-note 16{{'go' should be declared prior to the call site}} \
-// expected-error {{recursive template instantiation exceeded maximum depth of 16}}
+template<int N> struct X {
+  static int go(int a) noexcept(noexcept(X<N+1>::go(a))); // \
+// expected-error {{recursive template instantiation exceeded maximum depth of 16}} \
+// expected-note 9{{in instantiation of exception specification}} \
+// expected-note {{skipping 7 context}} \
+// expected-note {{use -ftemplate-depth}}
+};
 
 void f() {
-  int k = go(0); // \
-  // expected-note {{in instantiation of exception specification for 'go<int>' requested here}}
+  int k = X<0>::go(0); // \
+  // expected-note {{in instantiation of exception specification for 'go' requested here}}
 }

Modified: cfe/branches/release_39/test/SemaTemplate/instantiation-depth.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_39/test/SemaTemplate/instantiation-depth.cpp?rev=282636&r1=282635&r2=282636&view=diff
==============================================================================
--- cfe/branches/release_39/test/SemaTemplate/instantiation-depth.cpp (original)
+++ cfe/branches/release_39/test/SemaTemplate/instantiation-depth.cpp Wed Sep 28 16:25:06 2016
@@ -19,13 +19,12 @@ void test() {
 // RUN: %clang_cc1 -fsyntax-only -verify -ftemplate-depth 5 -ftemplate-backtrace-limit 4 -std=c++11 -DNOEXCEPT %s
 
 template<typename T> struct S {
-  S() noexcept(noexcept(T()));
-};
-struct T : S<T> {}; \
+  S() noexcept(noexcept(S<S>())); \
 // expected-error{{recursive template instantiation exceeded maximum depth of 5}} \
-// expected-note 4 {{in instantiation of exception spec}} \
+// expected-note 3 {{in instantiation of exception spec}} \
 // expected-note {{skipping 2 contexts in backtrace}} \
 // expected-note {{use -ftemplate-depth=N to increase recursive template instantiation depth}}
-T t; // expected-note {{implicit default constructor for 'T' first required here}}
+};
+S<void> t; // expected-note {{in instantiation of exception spec}}
 
 #endif




More information about the llvm-branch-commits mailing list