summaryrefslogtreecommitdiff
path: root/clang/test/CXX/temp/temp.param
diff options
context:
space:
mode:
Diffstat (limited to 'clang/test/CXX/temp/temp.param')
-rw-r--r--clang/test/CXX/temp/temp.param/p1.cpp12
-rw-r--r--clang/test/CXX/temp/temp.param/p10-0x.cpp13
-rw-r--r--clang/test/CXX/temp/temp.param/p10.cpp12
-rw-r--r--clang/test/CXX/temp/temp.param/p11-0x.cpp81
-rw-r--r--clang/test/CXX/temp/temp.param/p11.cpp15
-rw-r--r--clang/test/CXX/temp/temp.param/p12.cpp39
-rw-r--r--clang/test/CXX/temp/temp.param/p13.cpp14
-rw-r--r--clang/test/CXX/temp/temp.param/p14.cpp5
-rw-r--r--clang/test/CXX/temp/temp.param/p15-cxx0x.cpp24
-rw-r--r--clang/test/CXX/temp/temp.param/p15.cpp12
-rw-r--r--clang/test/CXX/temp/temp.param/p2.cpp22
-rw-r--r--clang/test/CXX/temp/temp.param/p3.cpp40
-rw-r--r--clang/test/CXX/temp/temp.param/p4.cpp21
-rw-r--r--clang/test/CXX/temp/temp.param/p5.cpp13
-rw-r--r--clang/test/CXX/temp/temp.param/p7.cpp15
-rw-r--r--clang/test/CXX/temp/temp.param/p8.cpp6
-rw-r--r--clang/test/CXX/temp/temp.param/p9-0x.cpp61
-rw-r--r--clang/test/CXX/temp/temp.param/p9.cpp23
18 files changed, 428 insertions, 0 deletions
diff --git a/clang/test/CXX/temp/temp.param/p1.cpp b/clang/test/CXX/temp/temp.param/p1.cpp
new file mode 100644
index 0000000..e9a9789
--- /dev/null
+++ b/clang/test/CXX/temp/temp.param/p1.cpp
@@ -0,0 +1,12 @@
+// Suppress 'no run line' failure.
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+template<template<> class C> class D; // expected-error{{template template parameter must have its own template parameters}}
+
+
+struct A {};
+template<class M,
+ class T = A, // expected-note{{previous default template argument defined here}}
+ class C> // expected-error{{template parameter missing a default argument}}
+class X0 {}; // expected-note{{template is declared here}}
+X0<int> x0; // expected-error{{too few template arguments for class template 'X0'}}
diff --git a/clang/test/CXX/temp/temp.param/p10-0x.cpp b/clang/test/CXX/temp/temp.param/p10-0x.cpp
new file mode 100644
index 0000000..37bb284
--- /dev/null
+++ b/clang/test/CXX/temp/temp.param/p10-0x.cpp
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
+
+template<typename> struct Y1;
+template<typename, int> struct Y2;
+
+template<class T1, class T2 = int> using B2 = T1;
+template<class T1 = int, class T2> using B2 = T1;
+
+template<template<class> class F, template<class> class G = Y1> using B2t = F<G<int>>;
+template<template<class> class F = Y2, template<class> class G> using B2t = F<G<int>>;
+
+template<int N, int M = 5> using B2n = Y2<int, N + M>;
+template<int N = 5, int M> using B2n = Y2<int, N + M>;
diff --git a/clang/test/CXX/temp/temp.param/p10.cpp b/clang/test/CXX/temp/temp.param/p10.cpp
new file mode 100644
index 0000000..b9dac75
--- /dev/null
+++ b/clang/test/CXX/temp/temp.param/p10.cpp
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+template<typename> struct Y1;
+template<typename, int> struct Y2;
+
+template<class T1, class T2 = int> class B2;
+template<class T1 = int, class T2> class B2;
+
+template<template<class, int> class, template<class> class = Y1> class B2t;
+template<template<class, int> class = Y2, template<class> class> class B2t;
+
+template<int N, int M = 5> class B2n;
+template<int N = 5, int M> class B2n;
diff --git a/clang/test/CXX/temp/temp.param/p11-0x.cpp b/clang/test/CXX/temp/temp.param/p11-0x.cpp
new file mode 100644
index 0000000..d2276a3
--- /dev/null
+++ b/clang/test/CXX/temp/temp.param/p11-0x.cpp
@@ -0,0 +1,81 @@
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
+
+// If a template-parameter of a class template or alias template has a default
+// template-argument, each subsequent template-parameter shall either have a
+// default template-argument supplied or be a template parameter pack.
+template<typename> struct vector;
+
+template<typename T = int, typename> struct X3t; // expected-error{{template parameter missing a default argument}} expected-note{{previous default template argument defined here}}
+template<typename T = int, typename> using A3t = int; // expected-error{{template parameter missing a default argument}} expected-note{{previous default template argument defined here}}
+template<int V = 0, int> struct X3nt; // expected-error{{template parameter missing a default argument}} expected-note{{previous default template argument defined here}}
+template<int V = 0, int> using A3nt = int; // expected-error{{template parameter missing a default argument}} expected-note{{previous default template argument defined here}}
+template<template<class> class M = vector, template<class> class> struct X3tt; // expected-error{{template parameter missing a default argument}} expected-note{{previous default template argument defined here}}
+template<template<class> class M = vector, template<class> class> using A3tt = int; // expected-error{{template parameter missing a default argument}} expected-note{{previous default template argument defined here}}
+
+template<typename T = int, typename ...Types> struct X2t;
+template<typename T = int, typename ...Types> using A2t = X2t<T, Types...>;
+template<int V = 0, int ...Values> struct X2nt;
+template<int V = 0, int ...Values> using A2nt = X2nt<V, Values...>;
+template<template<class> class M = vector, template<class> class... Metas>
+ struct X2tt;
+template<template<class> class M = vector, template<class> class... Metas>
+ using A2tt = X2tt<M, Metas...>;
+
+// If a template-parameter of a primary class template or alias template is a
+// template parameter pack, it shall be the last template-parameter.
+template<typename ...Types, // expected-error{{template parameter pack must be the last template parameter}}
+ int After, int After2>
+struct X0t;
+X0t<int> pr9789();
+template<typename ...Types, // expected-error{{template parameter pack must be the last template parameter}}
+ int After>
+using A0t = int;
+
+template<int ...Values, // expected-error{{template parameter pack must be the last template parameter}}
+ int After>
+struct X0nt;
+template<int ...Values, // expected-error{{template parameter pack must be the last template parameter}}
+ int After>
+using A0nt = int;
+
+template<template<typename> class ...Templates, // expected-error{{template parameter pack must be the last template parameter}}
+ int After>
+struct X0tt;
+template<template<typename> class ...Templates, // expected-error{{template parameter pack must be the last template parameter}}
+ int After>
+using A0tt = int;
+
+// [ Note: These are not requirements for function templates or class
+// template partial specializations because template arguments can be
+// deduced (14.8.2). -- end note]
+template<typename... Types> struct X1t;
+template<typename ...Types, typename T> struct X1t<T, Types...> { };
+
+template<int... Values> struct X1nt;
+template<int ...Values, int V> struct X1nt<V, Values...> { };
+
+template<template<int> class... Meta> struct X1tt;
+template<template<int> class... Meta, template<int> class M>
+ struct X1tt<M, Meta...> { };
+
+template<typename ...Types, typename T>
+void f1t(X1t<T, Types...>);
+
+template<int ...Values, int V>
+void f1nt(X1nt<V, Values...>);
+
+template<template<int> class... Meta, template<int> class M>
+void f1tt(X1tt<M, Meta...>);
+
+namespace DefaultTemplateArgsInFunction {
+ template<typename T = int, typename U> T &f0(U) { T *x = 0; return *x; }
+
+ void test_f0() {
+ int &ir0 = f0(3.14159);
+ int &ir1 = f0<int>(3.14159);
+ float &fr0 = f0<float>(3.14159);
+ }
+
+ template<> int &f0(int*);
+ template int &f0(double&);
+}
diff --git a/clang/test/CXX/temp/temp.param/p11.cpp b/clang/test/CXX/temp/temp.param/p11.cpp
new file mode 100644
index 0000000..5af0c4e
--- /dev/null
+++ b/clang/test/CXX/temp/temp.param/p11.cpp
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+template<typename> struct Y1;
+template<typename, int> struct Y2;
+
+template<class T1 = int, // expected-note{{previous default template argument defined here}}
+ class T2> // expected-error{{template parameter missing a default argument}}
+ class B1;
+
+template<template<class> class = Y1, // expected-note{{previous default template argument defined here}}
+ template<class> class> // expected-error{{template parameter missing a default argument}}
+ class B1t;
+
+template<int N = 5, // expected-note{{previous default template argument defined here}}
+ int M> // expected-error{{template parameter missing a default argument}}
+ class B1n;
diff --git a/clang/test/CXX/temp/temp.param/p12.cpp b/clang/test/CXX/temp/temp.param/p12.cpp
new file mode 100644
index 0000000..7be3879
--- /dev/null
+++ b/clang/test/CXX/temp/temp.param/p12.cpp
@@ -0,0 +1,39 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+template<typename> struct Y1; // expected-note{{too few template parameters in template template argument}}
+template<typename, int> struct Y2;
+
+// C++ [temp.param]p12:
+template<class T1,
+ class T2 = int> // expected-note{{previous default template argument defined here}}
+ class B3;
+template<class T1, typename T2> class B3;
+template<class T1,
+ typename T2 = float> // expected-error{{template parameter redefines default argument}}
+ class B3;
+
+template<template<class, int> class,
+ template<class> class = Y1> // expected-note{{previous default template argument defined here}}
+ class B3t;
+
+template<template<class, int> class, template<class> class> class B3t;
+
+template<template<class, int> class,
+ template<class> class = Y1> // expected-error{{template parameter redefines default argument}}
+ class B3t;
+
+template<int N,
+ int M = 5> // expected-note{{previous default template argument defined here}}
+ class B3n;
+
+template<int N, int M> class B3n;
+
+template<int N,
+ int M = 7> // expected-error{{template parameter redefines default argument}}
+ class B3n;
+
+// Check validity of default arguments
+template<template<class, int> class // expected-note{{previous template template parameter is here}}
+ = Y1> // expected-error{{template template argument has different template parameters than its corresponding template template parameter}}
+ class C1 {};
+
+C1<> c1; // expected-note{{while checking a default template argument}}
diff --git a/clang/test/CXX/temp/temp.param/p13.cpp b/clang/test/CXX/temp/temp.param/p13.cpp
new file mode 100644
index 0000000..7e7dbe5
--- /dev/null
+++ b/clang/test/CXX/temp/temp.param/p13.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+// The scope of atemplate-parameterextends from its point of
+// declaration until the end of its template. In particular, a
+// template-parameter can be used in the declaration of subsequent
+// template-parameters and their default arguments.
+
+template<class T, T* p, class U = T> class X { /* ... */ };
+// FIXME: template<class T> void f(T* p = new T);
+
+// Check for bogus template parameter shadow warning.
+template<template<class T> class,
+ template<class T> class>
+ class B1noshadow;
diff --git a/clang/test/CXX/temp/temp.param/p14.cpp b/clang/test/CXX/temp/temp.param/p14.cpp
new file mode 100644
index 0000000..a6c53c1
--- /dev/null
+++ b/clang/test/CXX/temp/temp.param/p14.cpp
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+// XFAIL: *
+
+// A template-parameter shall not be used in its own default argument.
+template<typename T = typename T::type> struct X; // expected-error{{default}}
diff --git a/clang/test/CXX/temp/temp.param/p15-cxx0x.cpp b/clang/test/CXX/temp/temp.param/p15-cxx0x.cpp
new file mode 100644
index 0000000..5fc57a4
--- /dev/null
+++ b/clang/test/CXX/temp/temp.param/p15-cxx0x.cpp
@@ -0,0 +1,24 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++11 -verify %s
+template<typename T> struct X;
+template<int I> struct Y;
+
+X<X<int>> *x1;
+
+Y<(1 >> 2)> *y1;
+Y<1 >> 2> *y2; // FIXME: expected-error{{expected unqualified-id}}
+
+X<X<X<X<X<int>>>>> *x2;
+
+template<> struct X<int> { };
+typedef X<int> X_int;
+struct Z : X_int { };
+
+void f(const X<int> x) {
+ (void)reinterpret_cast<X<int>>(x); // expected-error{{reinterpret_cast from}}
+ (void)reinterpret_cast<X<X<X<int>>>>(x); // expected-error{{reinterpret_cast from}}
+
+ X<X<int>> *x1;
+}
+
+template<typename T = void> struct X1 { };
+X1<X1<>> x1a;
diff --git a/clang/test/CXX/temp/temp.param/p15.cpp b/clang/test/CXX/temp/temp.param/p15.cpp
new file mode 100644
index 0000000..ee572e9
--- /dev/null
+++ b/clang/test/CXX/temp/temp.param/p15.cpp
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++98 -verify %s
+template<typename T> struct X;
+template<int I> struct Y;
+
+X<X<int> > *x1;
+X<X<int>> *x2; // expected-error{{a space is required between consecutive right angle brackets (use '> >')}}
+
+X<X<X<X<int>> // expected-error{{a space is required between consecutive right angle brackets (use '> >')}}
+ >> *x3; // expected-error{{a space is required between consecutive right angle brackets (use '> >')}}
+
+Y<(1 >> 2)> *y1;
+Y<1 >> 2> *y2; // expected-warning{{use of right-shift operator ('>>') in template argument will require parentheses in C++11}}
diff --git a/clang/test/CXX/temp/temp.param/p2.cpp b/clang/test/CXX/temp/temp.param/p2.cpp
new file mode 100644
index 0000000..fed6e9c
--- /dev/null
+++ b/clang/test/CXX/temp/temp.param/p2.cpp
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+// There is no semantic difference between class and typename in a
+// template-parameter. typename followed by an unqualified-id names a
+// template type parameter.
+template<class T> struct X;
+template<typename T> struct X;
+
+// typename followed by aqualified-id denotes the type in a non-type
+// parameter-declaration.
+template<typename T, typename T::type Value> struct Y0;
+template<typename T, typename X<T>::type Value> struct Y1;
+
+// A storage class shall not be specified in a template-parameter declaration.
+template<static int Value> struct Z; // FIXME: expect an error
+
+// Make sure that we properly disambiguate non-type template parameters that
+// start with 'class'.
+class X1 { };
+template<class X1 *xptr> struct Y2 { };
+
+// FIXME: add the example from p2
diff --git a/clang/test/CXX/temp/temp.param/p3.cpp b/clang/test/CXX/temp/temp.param/p3.cpp
new file mode 100644
index 0000000..dc40c4b
--- /dev/null
+++ b/clang/test/CXX/temp/temp.param/p3.cpp
@@ -0,0 +1,40 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+// A type-parameter defines its identifier to be a type-name (if
+// declared with class or typename) or template-name (if declared with
+// template) in the scope of the template declaration.
+template<typename T> struct X0 {
+ T* value;
+};
+
+template<template<class T> class Y> struct X1 {
+ Y<int> value;
+};
+
+// [Note: because of the name lookup rules, a template-parameter that
+// could be interpreted as either a non-type template-parameter or a
+// type-parameter (because its identifier is the name of an already
+// existing class) is taken as a type-parameter. For example,
+class T { /* ... */ }; // expected-note{{candidate constructor (the implicit copy constructor) not viable}}
+int i;
+
+template<class T, T i> struct X2 {
+ void f(T t)
+ {
+ T t1 = i; //template-parameters T and i
+ ::T t2 = ::i; // global namespace members T and i \
+ // expected-error{{no viable conversion}}
+ }
+};
+
+namespace PR6831 {
+ namespace NA { struct S; }
+ namespace NB { struct S; }
+
+ using namespace NA;
+ using namespace NB;
+
+ template <typename S> void foo();
+ template <int S> void bar();
+ template <template<typename> class S> void baz();
+}
diff --git a/clang/test/CXX/temp/temp.param/p4.cpp b/clang/test/CXX/temp/temp.param/p4.cpp
new file mode 100644
index 0000000..809fb20
--- /dev/null
+++ b/clang/test/CXX/temp/temp.param/p4.cpp
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+class X;
+
+// C++ [temp.param]p4
+typedef int INT;
+enum E { enum1, enum2 };
+template<int N> struct A1;
+template<INT N, INT M> struct A2;
+template<enum E x, E y> struct A3;
+template<int &X> struct A4;
+template<int *Ptr> struct A5;
+template<int (&f)(int, int)> struct A6;
+template<int (*fp)(float, double)> struct A7;
+template<int X::*pm> struct A8;
+template<float (X::*pmf)(float, int)> struct A9;
+template<typename T, T x> struct A10;
+
+template<float f> struct A11; // expected-error{{a non-type template parameter cannot have type 'float'}}
+
+template<void *Ptr> struct A12;
+template<int (*IncompleteArrayPtr)[]> struct A13;
diff --git a/clang/test/CXX/temp/temp.param/p5.cpp b/clang/test/CXX/temp/temp.param/p5.cpp
new file mode 100644
index 0000000..3cbb3b7
--- /dev/null
+++ b/clang/test/CXX/temp/temp.param/p5.cpp
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -verify %s -std=c++11
+
+template<const int I> struct S {
+ decltype(I) n;
+ int &&r = I;
+};
+S<5> s;
+
+template<typename T, T v> struct U {
+ decltype(v) n;
+ int &&r = v;
+};
+U<const int, 6> u;
diff --git a/clang/test/CXX/temp/temp.param/p7.cpp b/clang/test/CXX/temp/temp.param/p7.cpp
new file mode 100644
index 0000000..13f0367
--- /dev/null
+++ b/clang/test/CXX/temp/temp.param/p7.cpp
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+// A non-type template-parameter shall not be declared to have
+// floating point, class, or void type.
+struct A;
+
+template<double d> class X; // expected-error{{cannot have type}}
+template<double* pd> class Y; //OK
+template<double& rd> class Z; //OK
+
+template<A a> class X0; // expected-error{{cannot have type}}
+
+typedef void VOID;
+template<VOID a> class X01; // expected-error{{cannot have type}}
+
diff --git a/clang/test/CXX/temp/temp.param/p8.cpp b/clang/test/CXX/temp/temp.param/p8.cpp
new file mode 100644
index 0000000..fed048c
--- /dev/null
+++ b/clang/test/CXX/temp/temp.param/p8.cpp
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+template<int X[10]> struct A;
+template<int *X> struct A;
+template<int f(float, double)> struct B;
+typedef float FLOAT;
+template<int (*f)(FLOAT, double)> struct B;
diff --git a/clang/test/CXX/temp/temp.param/p9-0x.cpp b/clang/test/CXX/temp/temp.param/p9-0x.cpp
new file mode 100644
index 0000000..29a7549
--- /dev/null
+++ b/clang/test/CXX/temp/temp.param/p9-0x.cpp
@@ -0,0 +1,61 @@
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
+
+// A default template-argument may be specified for any kind of
+// template-parameter that is not a template parameter pack.
+template<typename ...Types = int> // expected-error{{template parameter pack cannot have a default argument}}
+struct X0;
+
+template<int ...Values = 0> // expected-error{{template parameter pack cannot have a default argument}}
+struct X1;
+
+template<typename T> struct vector;
+
+template<template<class> class ...Templates = vector> // expected-error{{template parameter pack cannot have a default argument}}
+struct X2;
+
+struct X3 {
+ template<typename T = int> // expected-error{{default template argument not permitted on a friend template}}
+ friend void f0(X3);
+
+ template<typename T = int>
+ friend void f1(X3) {
+ }
+};
+
+namespace PR8748 {
+ // Testcase 1
+ struct A0 { template<typename U> struct B; };
+ template<typename U = int> struct A0::B { };
+
+ // Testcase 2
+ template<typename T> struct A1 { template<typename U> struct B; };
+ template<typename T> template<typename U = int> struct A1<T>::B { }; // expected-error{{cannot add a default template argument to the definition of a member of a class template}}
+
+ // Testcase 3
+ template<typename T>
+ struct X2 {
+ void f0();
+ template<typename U> void f1();
+ };
+
+ template<typename T = int> void X2<T>::f0() { } // expected-error{{cannot add a default template argument to the definition of a member of a class template}}
+ template<typename T> template<typename U = int> void X2<T>::f1() { } // expected-error{{cannot add a default template argument to the definition of a member of a class template}}
+
+ namespace Inner {
+ template<typename T> struct X3;
+ template<typename T> void f2();
+ }
+
+ // Okay; not class members.
+ template<typename T = int> struct Inner::X3 { };
+ template<typename T = int> void Inner::f2() {}
+}
+
+namespace PR10069 {
+ template<typename T, T a, T b=0, T c=1>
+ T f(T x);
+
+ void g() {
+ f<unsigned int, 0>(0);
+ }
+}
diff --git a/clang/test/CXX/temp/temp.param/p9.cpp b/clang/test/CXX/temp/temp.param/p9.cpp
new file mode 100644
index 0000000..b2318c2
--- /dev/null
+++ b/clang/test/CXX/temp/temp.param/p9.cpp
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++98 -verify %s
+
+// A default template-argument shall not be specified in a function
+// template declaration or a function template definition
+template<typename T = int> // expected-warning{{default template arguments for a function template are a C++11 extension}}
+ void foo0(T);
+template<typename T = int> // expected-warning{{default template arguments for a function template are a C++11 extension}}
+ void foo1(T) { }
+
+// [...] nor in the template-parameter-list of the definition of a
+// member of a class template.
+template<int N>
+struct X0 {
+ void f();
+};
+
+template<int N = 0> // expected-error{{cannot add a default template argument}}
+void X0<N>::f() { }
+
+class X1 {
+ template<template<int> class TT = X0> // expected-error{{not permitted on a friend template}}
+ friend void f2();
+};