summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric Fiselier <eric@efcs.ca>2016-09-28 21:25:06 +0000
committerEric Fiselier <eric@efcs.ca>2016-09-28 21:25:06 +0000
commitc3709e72d22432f53f8e2f14354def31a96734fe (patch)
treef82fcf0eb0c726e3e0871d40183eb2a3da2886c1
parent07307f95d5c82d453cdc5c23f9ccd53d5ff75426 (diff)
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. :( ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/cfe/branches/release_39@282636 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/AST/DeclTemplate.h10
-rw-r--r--include/clang/Basic/DiagnosticSemaKinds.td4
-rw-r--r--include/clang/Sema/Sema.h23
-rw-r--r--lib/Sema/SemaDecl.cpp3
-rw-r--r--lib/Sema/SemaExpr.cpp5
-rw-r--r--lib/Sema/SemaTemplate.cpp13
-rw-r--r--lib/Sema/SemaTemplateInstantiate.cpp37
-rw-r--r--lib/Sema/SemaTemplateInstantiateDecl.cpp35
-rw-r--r--test/SemaTemplate/instantiate-self.cpp103
-rw-r--r--test/SemaTemplate/instantiation-depth-exception-spec.cpp15
-rw-r--r--test/SemaTemplate/instantiation-depth.cpp9
11 files changed, 206 insertions, 51 deletions
diff --git a/include/clang/AST/DeclTemplate.h b/include/clang/AST/DeclTemplate.h
index 4ac8cdc9be..d553e739c3 100644
--- a/include/clang/AST/DeclTemplate.h
+++ b/include/clang/AST/DeclTemplate.h
@@ -44,6 +44,8 @@ class VarTemplatePartialSpecializationDecl;
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
diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td
index 1203fe765b..1a05d4ab5e 100644
--- a/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/include/clang/Basic/DiagnosticSemaKinds.td
@@ -6917,6 +6917,10 @@ def err_in_class_initializer_not_yet_parsed
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; "
diff --git a/include/clang/Sema/Sema.h b/include/clang/Sema/Sema.h
index 10a8a5ac53..1cb8d2b331 100644
--- a/include/clang/Sema/Sema.h
+++ b/include/clang/Sema/Sema.h
@@ -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);
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index ea276a995d..41719d4e7b 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -9615,7 +9615,8 @@ void Sema::AddInitializerToDecl(Decl *RealDecl, Expr *Init,
}
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 ||
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp
index adcc38cbc4..e9023c8295 100644
--- a/lib/Sema/SemaExpr.cpp
+++ b/lib/Sema/SemaExpr.cpp
@@ -4522,6 +4522,11 @@ ExprResult Sema::BuildCXXDefaultArgExpr(SourceLocation CallLoc,
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;
{
diff --git a/lib/Sema/SemaTemplate.cpp b/lib/Sema/SemaTemplate.cpp
index 7fc5db82d3..72e499342f 100644
--- a/lib/Sema/SemaTemplate.cpp
+++ b/lib/Sema/SemaTemplate.cpp
@@ -3256,7 +3256,7 @@ SubstDefaultTemplateArgument(Sema &SemaRef,
// 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 &SemaRef,
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 &SemaRef,
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(TemplateDecl *Template,
}
// 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())
diff --git a/lib/Sema/SemaTemplateInstantiate.cpp b/lib/Sema/SemaTemplateInstantiate.cpp
index 48c6a506ee..65a5633bf0 100644
--- a/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/lib/Sema/SemaTemplateInstantiate.cpp
@@ -225,6 +225,10 @@ Sema::InstantiatingTemplate::InstantiatingTemplate(
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::InstantiatingTemplate(
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::InstantiatingTemplate(
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::InstantiatingTemplate(
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 PointOfInstantiation,
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(SourceLocation PointOfInstantiation,
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");
diff --git a/lib/Sema/SemaTemplateInstantiateDecl.cpp b/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 6a213953ec..dd3748fb53 100644
--- a/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -3360,6 +3360,13 @@ void Sema::InstantiateExceptionSpec(SourceLocation PointOfInstantiation,
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(SourceLocation PointOfInstantiation,
}
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::InstantiateVariableInitializer(
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::InstantiateVariableInitializer(
}
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(SourceLocation PointOfInstantiation,
// 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(SourceLocation PointOfInstantiation,
}
InstantiatingTemplate Inst(*this, PointOfInstantiation, Var);
- if (Inst.isInvalid())
+ if (Inst.isInvalid() || Inst.isAlreadyInstantiating())
return;
PrettyDeclStackTraceEntry CrashInfo(*this, Var, SourceLocation(),
"instantiating variable definition");
diff --git a/test/SemaTemplate/instantiate-self.cpp b/test/SemaTemplate/instantiate-self.cpp
index cfe902509f..916a01e63f 100644
--- a/test/SemaTemplate/instantiate-self.cpp
+++ b/test/SemaTemplate/instantiate-self.cpp
@@ -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
+}
diff --git a/test/SemaTemplate/instantiation-depth-exception-spec.cpp b/test/SemaTemplate/instantiation-depth-exception-spec.cpp
index 6caa4a60e6..3f64811bd1 100644
--- a/test/SemaTemplate/instantiation-depth-exception-spec.cpp
+++ b/test/SemaTemplate/instantiation-depth-exception-spec.cpp
@@ -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}}
}
diff --git a/test/SemaTemplate/instantiation-depth.cpp b/test/SemaTemplate/instantiation-depth.cpp
index c0b8bb2a12..17f84c170c 100644
--- a/test/SemaTemplate/instantiation-depth.cpp
+++ b/test/SemaTemplate/instantiation-depth.cpp
@@ -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