Home | History | Annotate | Download | only in temp.param
      1 // RUN: %clang_cc1 -std=c++0x -fsyntax-only -verify %s
      2 
      3 // If a template-parameter of a class template or alias template has a default
      4 // template-argument, each subsequent template-parameter shall either have a
      5 // default template-argument supplied or be a template parameter pack.
      6 template<typename> struct vector;
      7 
      8 template<typename T = int, typename> struct X3t; // expected-error{{template parameter missing a default argument}} expected-note{{previous default template argument defined here}}
      9 template<typename T = int, typename> using A3t = int; // expected-error{{template parameter missing a default argument}} expected-note{{previous default template argument defined here}}
     10 template<int V = 0, int> struct X3nt; // expected-error{{template parameter missing a default argument}} expected-note{{previous default template argument defined here}}
     11 template<int V = 0, int> using A3nt = int; // expected-error{{template parameter missing a default argument}} expected-note{{previous default template argument defined here}}
     12 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}}
     13 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}}
     14 
     15 template<typename T = int, typename ...Types> struct X2t;
     16 template<typename T = int, typename ...Types> using A2t = X2t<T, Types...>;
     17 template<int V = 0, int ...Values> struct X2nt;
     18 template<int V = 0, int ...Values> using A2nt = X2nt<V, Values...>;
     19 template<template<class> class M = vector, template<class> class... Metas>
     20   struct X2tt;
     21 template<template<class> class M = vector, template<class> class... Metas>
     22   using A2tt = X2tt<M, Metas...>;
     23 
     24 // If a template-parameter of a primary class template or alias template is a
     25 // template parameter pack, it shall be the last template-parameter.
     26 template<typename ...Types, // expected-error{{template parameter pack must be the last template parameter}}
     27          int After>
     28 struct X0t;
     29 template<typename ...Types, // expected-error{{template parameter pack must be the last template parameter}}
     30          int After>
     31 using A0t = int;
     32 
     33 template<int ...Values, // expected-error{{template parameter pack must be the last template parameter}}
     34          int After>
     35 struct X0nt;
     36 template<int ...Values, // expected-error{{template parameter pack must be the last template parameter}}
     37          int After>
     38 using A0nt = int;
     39 
     40 template<template<typename> class ...Templates, // expected-error{{template parameter pack must be the last template parameter}}
     41          int After>
     42 struct X0tt;
     43 template<template<typename> class ...Templates, // expected-error{{template parameter pack must be the last template parameter}}
     44          int After>
     45 using A0tt = int;
     46 
     47 // [ Note: These are not requirements for function templates or class
     48 // template partial specializations because template arguments can be
     49 // deduced (14.8.2). -- end note]
     50 template<typename... Types> struct X1t;
     51 template<typename ...Types, typename T> struct X1t<T, Types...> { };
     52 
     53 template<int... Values> struct X1nt;
     54 template<int ...Values, int V> struct X1nt<V, Values...> { };
     55 
     56 template<template<int> class... Meta> struct X1tt;
     57 template<template<int> class... Meta, template<int> class M>
     58   struct X1tt<M, Meta...> { };
     59 
     60 template<typename ...Types, typename T>
     61 void f1t(X1t<T, Types...>);
     62 
     63 template<int ...Values, int V>
     64 void f1nt(X1nt<V, Values...>);
     65 
     66 template<template<int> class... Meta, template<int> class M>
     67 void f1tt(X1tt<M, Meta...>);
     68 
     69 namespace DefaultTemplateArgsInFunction {
     70   template<typename T = int, typename U>  T &f0(U) { T *x = 0; return *x; }
     71 
     72   void test_f0() {
     73     int &ir0 = f0(3.14159);
     74     int &ir1 = f0<int>(3.14159);
     75     float &fr0 = f0<float>(3.14159);
     76   }
     77 
     78   template<> int &f0(int*);
     79   template int &f0(double&);
     80 }
     81