diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2017-01-26 20:40:47 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2017-01-26 20:40:47 +0000 |
commit | fe32c6a33461a8c60e18c0414d4844a47442328a (patch) | |
tree | 3cb647756006e0f69a9e57ec8072bf95522522ee /test/Parser/cxx1z-class-template-argument-deduction.cpp | |
parent | 56ba9cc1c9155ff7130320eabea7cd6da70dd49e (diff) |
PR0091R3: Implement parsing support for using templates as types.
This change adds a new type node, DeducedTemplateSpecializationType, to
represent a type template name that has been used as a type. This is modeled
around AutoType, and shares a common base class for representing a deduced
placeholder type.
We allow deduced class template types in a few more places than the standard
does: in conditions and for-range-declarators, and in new-type-ids. This is
consistent with GCC and with discussion on the core reflector. This patch
does not yet support deduced class template types being named in typename
specifiers.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@293207 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/Parser/cxx1z-class-template-argument-deduction.cpp')
-rw-r--r-- | test/Parser/cxx1z-class-template-argument-deduction.cpp | 131 |
1 files changed, 131 insertions, 0 deletions
diff --git a/test/Parser/cxx1z-class-template-argument-deduction.cpp b/test/Parser/cxx1z-class-template-argument-deduction.cpp new file mode 100644 index 0000000000..e53d64f2ed --- /dev/null +++ b/test/Parser/cxx1z-class-template-argument-deduction.cpp @@ -0,0 +1,131 @@ +// RUN: %clang_cc1 -std=c++1z -fcxx-exceptions -verify %s + +template<typename T> struct A {}; // expected-note 31{{declared here}} + +// Make sure we still correctly parse cases where a template can appear without arguments. +namespace template_template_arg { + template<template<typename> typename> struct X {}; + template<typename> struct Y {}; + + X<A> xa; + Y<A> ya; // expected-error {{requires template arguments}} + X<::A> xcca; + Y<::A> ycca; // expected-error {{requires template arguments}} + + template<template<typename> typename = A> struct XD {}; + template<typename = A> struct YD {}; // expected-error {{requires template arguments}} + template<template<typename> typename = ::A> struct XCCD {}; + template<typename = ::A> struct YCCD {}; // expected-error {{requires template arguments}} + + // FIXME: replacing the invalid type with 'int' here is horrible + template <A a = A<int>()> class C { }; // expected-error {{requires template arguments}} expected-error {{not implicitly convertible to 'int'}} + template<typename T = A> struct G { }; // expected-error {{requires template arguments}} +} + +namespace injected_class_name { + template<typename T> struct A { + A(T); + void f(int) { + A a = 1; + injected_class_name::A b = 1; // expected-error {{not yet supported}} + } + void f(T); + }; + A<short> ai = 1; + A<double>::A b(1); // expected-error {{constructor name}} +} + +struct member { + A a; // expected-error {{requires template arguments}} + A *b; // expected-error {{requires template arguments}} + const A c; // expected-error {{requires template arguments}} + + void f() throw (A); // expected-error {{requires template arguments}} + + friend A; // expected-error {{requires template arguments; argument deduction not allowed in friend declaration}} + + operator A(); // expected-error {{requires template arguments; argument deduction not allowed in conversion function type}} + + static A x; // expected-error {{requires an initializer}} + static A y = 0; // expected-error {{not yet supported}} +}; + +namespace in_typedef { + typedef A *AutoPtr; // expected-error {{requires template arguments; argument deduction not allowed in typedef}} + typedef A (*PFun)(int a); // expected-error{{requires template arguments; argument deduction not allowed in typedef}} + typedef A Fun(int a) -> decltype(a + a); // expected-error{{requires template arguments; argument deduction not allowed in function return type}} +} + +namespace stmt { + void g(A a) { // expected-error{{requires template arguments; argument deduction not allowed in function prototype}} + try { } + catch (A &a) { } // expected-error{{requires template arguments; argument deduction not allowed in exception declaration}} + catch (const A a) { } // expected-error{{requires template arguments; argument deduction not allowed in exception declaration}} + try { } catch (A a) { } // expected-error{{requires template arguments; argument deduction not allowed in exception declaration}} + + // FIXME: The standard only permits class template argument deduction in a + // simple-declaration or cast. We also permit it in conditions, + // for-range-declarations, member-declarations for static data members, and + // new-expressions, because not doing so would be bizarre. + A local = 0; // expected-error {{not yet supported}} + static A local_static = 0; // expected-error {{not yet supported}} + static thread_local A thread_local_static = 0; // expected-error {{not yet supported}} + if (A a = 0) {} // expected-error {{not yet supported}} + if (A a = 0; a) {} // expected-error {{not yet supported}} + switch (A a = 0) {} // expected-error {{not yet supported}} + switch (A a = 0; a) {} // expected-error {{not yet supported}} + for (A a = 0; a; /**/) {} // expected-error {{not yet supported}} + for (/**/; A a = 0; /**/) {} // expected-error {{not yet supported}} + while (A a = 0) {} // expected-error {{not yet supported}} + int arr[3]; + for (A a : arr) {} // expected-error {{not yet supported}} + } + + namespace std { + class type_info; + } +} + +namespace expr { + template<typename T> struct U {}; + void j() { + (void)typeid(A); // expected-error{{requires template arguments; argument deduction not allowed here}} + (void)sizeof(A); // expected-error{{requires template arguments; argument deduction not allowed here}} + (void)__alignof(A); // expected-error{{requires template arguments; argument deduction not allowed here}} + + U<A> v; // expected-error {{requires template arguments}} + + int n; + (void)dynamic_cast<A&>(n); // expected-error{{requires template arguments; argument deduction not allowed here}} + (void)static_cast<A*>(&n); // expected-error{{requires template arguments; argument deduction not allowed here}} + (void)reinterpret_cast<A*>(&n); // expected-error{{requires template arguments; argument deduction not allowed here}} + (void)const_cast<A>(n); // expected-error{{requires template arguments; argument deduction not allowed here}} + (void)*(A*)(&n); // expected-error{{requires template arguments; argument deduction not allowed here}} + + (void)A(n); // expected-error {{not yet supported}} + (void)A{n}; // expected-error {{not yet supported}} + (void)new A(n); // expected-error {{not yet supported}} + (void)new A{n}; // expected-error {{not yet supported}} + // FIXME: We should diagnose the lack of an initializer here. + (void)new A; // expected-error {{not yet supported}} + } +} + +namespace decl { + enum E : A {}; // expected-error{{requires template arguments; argument deduction not allowed here}} + struct F : A {}; // expected-error{{expected class name}} + + using B = A; // expected-error{{requires template arguments}} + + auto k() -> A; // expected-error{{requires template arguments}} + + A a; // expected-error {{requires an initializer}} + A b = 0; // expected-error {{not yet supported}} + A (parens) = 0; // expected-error {{cannot use parentheses when declaring variable with deduced class template specialization type}} + A *p = 0; // expected-error {{cannot form pointer to deduced class template specialization type}} + A &r = *p; // expected-error {{cannot form reference to deduced class template specialization type}} + A arr[3] = 0; // expected-error {{cannot form array of deduced class template specialization type}} + A F::*pm = 0; // expected-error {{cannot form pointer to deduced class template specialization type}} + A (*fp)() = 0; // expected-error {{cannot form function returning deduced class template specialization type}} + A [x, y] = 0; // expected-error {{cannot be declared with type 'A'}} expected-error {{not yet supported}} +} |