xref: /llvm-project/clang/test/CXX/temp/temp.param/p9-0x.cpp (revision 9ca5c425826329d5b23300bbc8a1a7c10a19c64d)
1*9ca5c425SRichard Smith // RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
20da4a99aSDouglas Gregor 
30da4a99aSDouglas Gregor // A default template-argument may be specified for any kind of
40da4a99aSDouglas Gregor // template-parameter that is not a template parameter pack.
50da4a99aSDouglas Gregor template<typename ...Types = int> // expected-error{{template parameter pack cannot have a default argument}}
60da4a99aSDouglas Gregor struct X0;
70da4a99aSDouglas Gregor 
80da4a99aSDouglas Gregor template<int ...Values = 0> // expected-error{{template parameter pack cannot have a default argument}}
90da4a99aSDouglas Gregor struct X1;
100da4a99aSDouglas Gregor 
11f550077eSDouglas Gregor template<typename T> struct vector;
12f550077eSDouglas Gregor 
13f550077eSDouglas Gregor template<template<class> class ...Templates = vector> // expected-error{{template parameter pack cannot have a default argument}}
14f550077eSDouglas Gregor struct X2;
15a99fb4c7SDouglas Gregor 
16a99fb4c7SDouglas Gregor struct X3 {
17a99fb4c7SDouglas Gregor   template<typename T = int> // expected-error{{default template argument not permitted on a friend template}}
18a99fb4c7SDouglas Gregor   friend void f0(X3);
19a99fb4c7SDouglas Gregor 
20a99fb4c7SDouglas Gregor   template<typename T = int>
f1(X3)21a99fb4c7SDouglas Gregor   friend void f1(X3) {
22a99fb4c7SDouglas Gregor   }
23a99fb4c7SDouglas Gregor };
24a99fb4c7SDouglas Gregor 
254d5c2976SDouglas Gregor namespace PR8748 {
26a99fb4c7SDouglas Gregor   // Testcase 1
27a99fb4c7SDouglas Gregor   struct A0 { template<typename U> struct B; };
284d5c2976SDouglas Gregor   template<typename U = int> struct A0::B { };
29a99fb4c7SDouglas Gregor 
30a99fb4c7SDouglas Gregor   // Testcase 2
31a99fb4c7SDouglas Gregor   template<typename T> struct A1 { template<typename U> struct B; };
32a99fb4c7SDouglas Gregor   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}}
33a99fb4c7SDouglas Gregor 
34a99fb4c7SDouglas Gregor   // Testcase 3
35a99fb4c7SDouglas Gregor   template<typename T>
36a99fb4c7SDouglas Gregor   struct X2 {
37a99fb4c7SDouglas Gregor     void f0();
38a99fb4c7SDouglas Gregor     template<typename U> void f1();
39a99fb4c7SDouglas Gregor   };
40a99fb4c7SDouglas Gregor 
f0()41a99fb4c7SDouglas Gregor   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}}
f1()42a99fb4c7SDouglas Gregor   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}}
43a99fb4c7SDouglas Gregor 
44a99fb4c7SDouglas Gregor   namespace Inner {
45a99fb4c7SDouglas Gregor     template<typename T> struct X3;
46a99fb4c7SDouglas Gregor     template<typename T> void f2();
47a99fb4c7SDouglas Gregor   }
48a99fb4c7SDouglas Gregor 
49a99fb4c7SDouglas Gregor   // Okay; not class members.
50a99fb4c7SDouglas Gregor   template<typename T = int> struct Inner::X3 { };
f2()51a99fb4c7SDouglas Gregor   template<typename T = int> void Inner::f2() {}
52a99fb4c7SDouglas Gregor }
532f157c9aSDouglas Gregor 
542f157c9aSDouglas Gregor namespace PR10069 {
552f157c9aSDouglas Gregor   template<typename T, T a, T b=0, T c=1>
562f157c9aSDouglas Gregor   T f(T x);
572f157c9aSDouglas Gregor 
g()582f157c9aSDouglas Gregor   void g() {
592f157c9aSDouglas Gregor     f<unsigned int, 0>(0);
602f157c9aSDouglas Gregor   }
612f157c9aSDouglas Gregor }
62