diff options
author | David Majnemer <david.majnemer@gmail.com> | 2013-08-28 23:48:32 +0000 |
---|---|---|
committer | David Majnemer <david.majnemer@gmail.com> | 2013-08-28 23:48:32 +0000 |
commit | 8918920a329506ea76693876cc8f23af145a6aaa (patch) | |
tree | 12cffd36b8397a1e04b4ad0b9aca982ff2046519 /clang/test | |
parent | 4c459bcd472c32e68654c0ffea48a5978819c4e7 (diff) | |
download | bcm5719-llvm-8918920a329506ea76693876cc8f23af145a6aaa.tar.gz bcm5719-llvm-8918920a329506ea76693876cc8f23af145a6aaa.zip |
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
Diffstat (limited to 'clang/test')
-rw-r--r-- | clang/test/CodeGenCXX/mangle.cpp | 23 | ||||
-rw-r--r-- | clang/test/SemaCXX/cxx1y-deduced-return-type.cpp | 9 | ||||
-rw-r--r-- | clang/test/SemaTemplate/default-arguments-cxx0x.cpp | 31 | ||||
-rw-r--r-- | clang/test/SemaTemplate/default-arguments.cpp | 28 |
4 files changed, 83 insertions, 8 deletions
diff --git a/clang/test/CodeGenCXX/mangle.cpp b/clang/test/CodeGenCXX/mangle.cpp index a9daa0df619..f03f499fe13 100644 --- a/clang/test/CodeGenCXX/mangle.cpp +++ b/clang/test/CodeGenCXX/mangle.cpp @@ -910,3 +910,26 @@ namespace test40 { }; 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/clang/test/SemaCXX/cxx1y-deduced-return-type.cpp b/clang/test/SemaCXX/cxx1y-deduced-return-type.cpp index 26d776f375d..9e779bf170a 100644 --- a/clang/test/SemaCXX/cxx1y-deduced-return-type.cpp +++ b/clang/test/SemaCXX/cxx1y-deduced-return-type.cpp @@ -399,3 +399,12 @@ namespace CurrentInstantiation { 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/clang/test/SemaTemplate/default-arguments-cxx0x.cpp b/clang/test/SemaTemplate/default-arguments-cxx0x.cpp index 4c815f65587..4cfd7a5843f 100644 --- a/clang/test/SemaTemplate/default-arguments-cxx0x.cpp +++ b/clang/test/SemaTemplate/default-arguments-cxx0x.cpp @@ -25,3 +25,34 @@ void g1() { 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/clang/test/SemaTemplate/default-arguments.cpp b/clang/test/SemaTemplate/default-arguments.cpp index aca5c972adb..439a3039211 100644 --- a/clang/test/SemaTemplate/default-arguments.cpp +++ b/clang/test/SemaTemplate/default-arguments.cpp @@ -47,11 +47,13 @@ template<typename T> struct X1 { }; 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 @@ struct X2 { }; }; -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 @@ namespace PR16288 { 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}} +} |