Sema: Subst type default template args earlier
Summary:
We would not perform substitution at an appropriate point, allowing strange
results to appear. We would accepts things that we shouldn't or mangle things incorrectly. Note that this hasn't fixed the other cases like
template-template parameters or non-type template parameters.
Reviewers: doug.gregor, rjmccall, rsmith
Reviewed By: rsmith
CC: cfe-commits
Differential Revision: http://llvm-reviews.chandlerc.com/D1507
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@189540 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/test/CodeGenCXX/mangle.cpp b/test/CodeGenCXX/mangle.cpp
index a9daa0d..f03f499 100644
--- a/test/CodeGenCXX/mangle.cpp
+++ b/test/CodeGenCXX/mangle.cpp
@@ -910,3 +910,26 @@
};
void g() { f(); }
}
+
+namespace test41 {
+ // CHECK: define linkonce_odr void @_ZN6test414funcINS_1XEEEvNS_3fooILi20ES1_EE
+ template <int i, class T> struct foo {
+ template <class T2 = T> friend void func(foo x) {}
+ };
+
+ struct X {};
+
+ void g() { func(foo<20, X>()); }
+}
+
+namespace test42 {
+ // CHECK: define linkonce_odr void @_ZN6test424funcINS_1XEEEvNS_3fooILi20ES1_EE
+ template <int i, template <class> class T> struct foo {
+ template <template <class> class T2 = T> friend void func(foo x) {}
+ };
+
+ template <class V> struct X {
+ };
+
+ void g() { func(foo<20, X>()); }
+}
diff --git a/test/SemaCXX/cxx1y-deduced-return-type.cpp b/test/SemaCXX/cxx1y-deduced-return-type.cpp
index 26d776f..9e779bf 100644
--- a/test/SemaCXX/cxx1y-deduced-return-type.cpp
+++ b/test/SemaCXX/cxx1y-deduced-return-type.cpp
@@ -399,3 +399,12 @@
template<typename T> auto U<T>::f() { return T(); }
template int U<short>::g(); // ok
}
+
+namespace WithDefaultArgs {
+ template<typename U> struct A {
+ template<typename T = U> friend auto f(A) { return []{}; }
+ };
+ template<typename T> void f();
+ using T = decltype(f(A<int>()));
+ using T = decltype(f<int>(A<int>()));
+}
diff --git a/test/SemaTemplate/default-arguments-cxx0x.cpp b/test/SemaTemplate/default-arguments-cxx0x.cpp
index 4c815f6..4cfd7a5 100644
--- a/test/SemaTemplate/default-arguments-cxx0x.cpp
+++ b/test/SemaTemplate/default-arguments-cxx0x.cpp
@@ -25,3 +25,34 @@
float &fr = f1(15);
int &ir = f1(HasValue());
}
+
+namespace PR16689 {
+ template <typename T1, typename T2> class tuple {
+ public:
+ template <typename = T2>
+ constexpr tuple() {}
+ };
+ template <class X, class... Y> struct a : public X {
+ using X::X;
+ };
+ auto x = a<tuple<int, int> >();
+}
+
+namespace PR16975 {
+ template <typename...> struct is {
+ constexpr operator bool() const { return false; }
+ };
+
+ template <typename... Types>
+ struct bar {
+ template <typename T,
+ bool = is<Types...>()>
+ bar(T);
+ };
+
+ struct baz : public bar<> {
+ using bar::bar;
+ };
+
+ baz data{0};
+}
diff --git a/test/SemaTemplate/default-arguments.cpp b/test/SemaTemplate/default-arguments.cpp
index aca5c97..439a303 100644
--- a/test/SemaTemplate/default-arguments.cpp
+++ b/test/SemaTemplate/default-arguments.cpp
@@ -47,11 +47,13 @@
template<typename T>
struct X2 {
- template<typename U = typename X1<T>::type> // expected-error{{no type named}}
- struct Inner1 { };
+ template<typename U = typename X1<T>::type> // expected-error{{no type named 'type' in 'X1<int>'}} \
+ // expected-error{{no type named 'type' in 'X1<char>'}}
+ struct Inner1 { }; // expected-note{{template is declared here}}
- template<T Value = X1<T>::value> // expected-error{{no member named 'value'}}
- struct NonType1 { };
+ template<T Value = X1<T>::value> // expected-error{{no member named 'value' in 'X1<int>'}} \
+ // expected-error{{no member named 'value' in 'X1<char>'}}
+ struct NonType1 { }; // expected-note{{template is declared here}}
template<T Value>
struct Inner2 { };
@@ -67,17 +69,17 @@
};
};
-X2<int> x2i;
+X2<int> x2i; // expected-note{{in instantiation of template class 'X2<int>' requested here}}
X2<int>::Inner1<float> x2iif;
-X2<int>::Inner1<> x2bad; // expected-note{{instantiation of default argument}}
+X2<int>::Inner1<> x2bad; // expected-error{{too few template arguments for class template 'Inner1'}}
X2<int>::NonType1<'a'> x2_nontype1;
-X2<int>::NonType1<> x2_nontype1_bad; // expected-note{{instantiation of default argument}}
+X2<int>::NonType1<> x2_nontype1_bad; // expected-error{{too few template arguments for class template 'NonType1'}}
// Check multi-level substitution into template type arguments
X2<int>::Inner3<float>::VeryInner<> vi;
-X2<char>::Inner3<int>::NonType2<> x2_deep_nontype;
+X2<char>::Inner3<int>::NonType2<> x2_deep_nontype; // expected-note{{in instantiation of template class 'X2<char>' requested here}}
template<typename T, typename U>
struct is_same { static const bool value = false; };
@@ -147,3 +149,13 @@
template<typename T, typename U>
void S<X>::f() {}
}
+
+namespace DR1635 {
+ template <class T> struct X {
+ template <class U = typename T::type> static void f(int) {} // expected-error {{type 'int' cannot be used prior to '::' because it has no members}} \
+ // expected-warning {{C++11}}
+ static void f(...) {}
+ };
+
+ int g() { X<int>::f(0); } // expected-note {{in instantiation of template class 'DR1635::X<int>' requested here}}
+}