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
llvm-svn: 189540
diff --git a/clang/test/SemaTemplate/default-arguments.cpp b/clang/test/SemaTemplate/default-arguments.cpp
index aca5c97..439a303 100644
--- a/clang/test/SemaTemplate/default-arguments.cpp
+++ b/clang/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}}
+}