2013-08-28 08:13:42 +08:00
|
|
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
|
2015-12-10 09:07:17 +08:00
|
|
|
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s
|
|
|
|
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
|
2009-02-10 08:24:35 +08:00
|
|
|
|
|
|
|
template<template<typename T> class X> struct A; // expected-note 2{{previous template template parameter is here}}
|
|
|
|
|
|
|
|
template<template<typename T, int I> class X> struct B; // expected-note{{previous template template parameter is here}}
|
|
|
|
|
2017-01-01 05:41:23 +08:00
|
|
|
template<template<int I> class X> struct C; // expected-note 2{{previous non-type template parameter with type 'int' is here}}
|
2009-02-10 08:24:35 +08:00
|
|
|
|
|
|
|
template<class> struct X; // expected-note{{too few template parameters in template template argument}}
|
|
|
|
template<int N> struct Y; // expected-note{{template parameter has a different kind in template argument}}
|
|
|
|
template<long N> struct Ylong; // expected-note{{template non-type parameter has a different type 'long' in template argument}}
|
2017-01-01 05:41:23 +08:00
|
|
|
template<const int &N> struct Yref; // expected-note{{template non-type parameter has a different type 'const int &' in template argument}}
|
2009-02-10 08:24:35 +08:00
|
|
|
|
|
|
|
namespace N {
|
|
|
|
template<class> struct Z;
|
|
|
|
}
|
|
|
|
template<class, class> struct TooMany; // expected-note{{too many template parameters in template template argument}}
|
|
|
|
|
|
|
|
|
|
|
|
A<X> *a1;
|
|
|
|
A<N::Z> *a2;
|
|
|
|
A< ::N::Z> *a3;
|
|
|
|
|
Implement parsing of nested-name-specifiers that involve template-ids, e.g.,
std::vector<int>::allocator_type
When we parse a template-id that names a type, it will become either a
template-id annotation (which is a parsed representation of a
template-id that has not yet been through semantic analysis) or a
typename annotation (where semantic analysis has resolved the
template-id to an actual type), depending on the context. We only
produce a type in contexts where we know that we only need type
information, e.g., in a type specifier. Otherwise, we create a
template-id annotation that can later be "upgraded" by transforming it
into a typename annotation when the parser needs a type. This occurs,
for example, when we've parsed "std::vector<int>" above and then see
the '::' after it. However, it means that when writing something like
this:
template<> class Outer::Inner<int> { ... };
We have two tokens to represent Outer::Inner<int>: one token for the
nested name specifier Outer::, and one template-id annotation token
for Inner<int>, which will be passed to semantic analysis to define
the class template specialization.
Most of the churn in the template tests in this patch come from an
improvement in our error recovery from ill-formed template-ids.
llvm-svn: 65467
2009-02-26 03:37:18 +08:00
|
|
|
A<Y> *a4; // expected-error{{template template argument has different template parameters than its corresponding template template parameter}}
|
|
|
|
A<TooMany> *a5; // expected-error{{template template argument has different template parameters than its corresponding template template parameter}}
|
|
|
|
B<X> *a6; // expected-error{{template template argument has different template parameters than its corresponding template template parameter}}
|
2009-02-10 08:24:35 +08:00
|
|
|
C<Y> *a7;
|
Implement parsing of nested-name-specifiers that involve template-ids, e.g.,
std::vector<int>::allocator_type
When we parse a template-id that names a type, it will become either a
template-id annotation (which is a parsed representation of a
template-id that has not yet been through semantic analysis) or a
typename annotation (where semantic analysis has resolved the
template-id to an actual type), depending on the context. We only
produce a type in contexts where we know that we only need type
information, e.g., in a type specifier. Otherwise, we create a
template-id annotation that can later be "upgraded" by transforming it
into a typename annotation when the parser needs a type. This occurs,
for example, when we've parsed "std::vector<int>" above and then see
the '::' after it. However, it means that when writing something like
this:
template<> class Outer::Inner<int> { ... };
We have two tokens to represent Outer::Inner<int>: one token for the
nested name specifier Outer::, and one template-id annotation token
for Inner<int>, which will be passed to semantic analysis to define
the class template specialization.
Most of the churn in the template tests in this patch come from an
improvement in our error recovery from ill-formed template-ids.
llvm-svn: 65467
2009-02-26 03:37:18 +08:00
|
|
|
C<Ylong> *a8; // expected-error{{template template argument has different template parameters than its corresponding template template parameter}}
|
2017-01-01 05:41:23 +08:00
|
|
|
C<Yref> *a9; // expected-error{{template template argument has different template parameters than its corresponding template template parameter}}
|
2009-02-10 08:24:35 +08:00
|
|
|
|
2009-11-11 09:00:40 +08:00
|
|
|
template<typename T> void f(int);
|
2009-02-10 08:24:35 +08:00
|
|
|
|
2009-11-11 09:00:40 +08:00
|
|
|
A<f> *a9; // expected-error{{must be a class template}}
|
2009-02-10 08:24:35 +08:00
|
|
|
|
2011-04-15 05:45:45 +08:00
|
|
|
// Evil digraph '<:' is parsed as '[', expect error.
|
2015-12-10 09:07:17 +08:00
|
|
|
A<::N::Z> *a10;
|
|
|
|
#if __cplusplus <= 199711L
|
|
|
|
// expected-error@-2 {{found '<::' after a template name which forms the digraph '<:' (aka '[') and a ':', did you mean '< ::'?}}
|
|
|
|
#endif
|
2011-04-15 05:45:45 +08:00
|
|
|
|
|
|
|
// Do not do a digraph correction here.
|
|
|
|
A<: :N::Z> *a11; // expected-error{{expected expression}} \
|
|
|
|
expected-error{{C++ requires a type specifier for all declarations}}
|
2010-08-06 22:15:26 +08:00
|
|
|
|
|
|
|
// PR7807
|
|
|
|
namespace N {
|
|
|
|
template <typename, typename = int>
|
|
|
|
struct X
|
|
|
|
{ };
|
|
|
|
|
|
|
|
template <typename ,int>
|
|
|
|
struct Y
|
|
|
|
{ X<int> const_ref(); };
|
|
|
|
|
|
|
|
template <template<typename,int> class TT, typename T, int N>
|
|
|
|
int operator<<(int, TT<T, N> a) { // expected-note{{candidate template ignored}}
|
|
|
|
0 << a.const_ref(); // expected-error{{invalid operands to binary expression ('int' and 'X<int>')}}
|
|
|
|
}
|
|
|
|
|
|
|
|
void f0( Y<int,1> y){ 1 << y; } // expected-note{{in instantiation of function template specialization 'N::operator<<<Y, int, 1>' requested here}}
|
|
|
|
}
|
2012-03-07 09:09:33 +08:00
|
|
|
|
|
|
|
// PR12179
|
2015-12-10 09:07:17 +08:00
|
|
|
template <typename Primitive, template <Primitive...> class F>
|
|
|
|
#if __cplusplus <= 199711L
|
|
|
|
// expected-warning@-2 {{variadic templates are a C++11 extension}}
|
|
|
|
#endif
|
|
|
|
|
2012-03-07 09:09:33 +08:00
|
|
|
struct unbox_args {
|
|
|
|
typedef typename Primitive::template call<F> x;
|
|
|
|
};
|
2013-08-28 13:45:53 +08:00
|
|
|
|
2015-12-10 09:07:17 +08:00
|
|
|
template <template <typename> class... Templates>
|
|
|
|
#if __cplusplus <= 199711L
|
|
|
|
// expected-warning@-2 {{variadic templates are a C++11 extension}}
|
|
|
|
#endif
|
|
|
|
|
2016-01-11 19:39:00 +08:00
|
|
|
struct template_tuple {
|
|
|
|
#if __cplusplus >= 201103L
|
|
|
|
static constexpr int N = sizeof...(Templates);
|
|
|
|
#endif
|
|
|
|
};
|
2013-08-28 08:00:27 +08:00
|
|
|
template <typename T>
|
|
|
|
struct identity {};
|
2015-12-10 09:07:17 +08:00
|
|
|
template <template <typename> class... Templates>
|
|
|
|
#if __cplusplus <= 199711L
|
|
|
|
// expected-warning@-2 {{variadic templates are a C++11 extension}}
|
|
|
|
#endif
|
|
|
|
|
2013-08-28 08:00:27 +08:00
|
|
|
template_tuple<Templates...> f7() {}
|
|
|
|
|
2016-01-11 19:39:00 +08:00
|
|
|
#if __cplusplus >= 201103L
|
|
|
|
struct S : public template_tuple<identity, identity> {
|
|
|
|
static_assert(N == 2, "Number of template arguments incorrect");
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2013-08-28 08:00:27 +08:00
|
|
|
void foo() {
|
|
|
|
f7<identity>();
|
|
|
|
}
|