1762bb9d0ad20320b9f97a841dce57ba5e8e48b07Richard Smith// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
21ed64765624d6f5226dd213e220e038b459972d1Douglas Gregor
33e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith// If a template-parameter of a class template or alias template has a default
43e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith// template-argument, each subsequent template-parameter shall either have a
53e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith// default template-argument supplied or be a template parameter pack.
61ed64765624d6f5226dd213e220e038b459972d1Douglas Gregortemplate<typename> struct vector;
71ed64765624d6f5226dd213e220e038b459972d1Douglas Gregor
83e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smithtemplate<typename T = int, typename> struct X3t; // expected-error{{template parameter missing a default argument}} expected-note{{previous default template argument defined here}}
93e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smithtemplate<typename T = int, typename> using A3t = int; // expected-error{{template parameter missing a default argument}} expected-note{{previous default template argument defined here}}
103e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smithtemplate<int V = 0, int> struct X3nt; // expected-error{{template parameter missing a default argument}} expected-note{{previous default template argument defined here}}
113e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smithtemplate<int V = 0, int> using A3nt = int; // expected-error{{template parameter missing a default argument}} expected-note{{previous default template argument defined here}}
123e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smithtemplate<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}}
133e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smithtemplate<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}}
143e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith
151ed64765624d6f5226dd213e220e038b459972d1Douglas Gregortemplate<typename T = int, typename ...Types> struct X2t;
163e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smithtemplate<typename T = int, typename ...Types> using A2t = X2t<T, Types...>;
171ed64765624d6f5226dd213e220e038b459972d1Douglas Gregortemplate<int V = 0, int ...Values> struct X2nt;
183e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smithtemplate<int V = 0, int ...Values> using A2nt = X2nt<V, Values...>;
191ed64765624d6f5226dd213e220e038b459972d1Douglas Gregortemplate<template<class> class M = vector, template<class> class... Metas>
201ed64765624d6f5226dd213e220e038b459972d1Douglas Gregor  struct X2tt;
213e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smithtemplate<template<class> class M = vector, template<class> class... Metas>
223e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  using A2tt = X2tt<M, Metas...>;
231ed64765624d6f5226dd213e220e038b459972d1Douglas Gregor
243e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith// If a template-parameter of a primary class template or alias template is a
253e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith// template parameter pack, it shall be the last template-parameter.
261ed64765624d6f5226dd213e220e038b459972d1Douglas Gregortemplate<typename ...Types, // expected-error{{template parameter pack must be the last template parameter}}
271368e58ae0eb3d92df9fa5538349b6adf6448d15David Blaikie         int After, int After2>
281ed64765624d6f5226dd213e220e038b459972d1Douglas Gregorstruct X0t;
291368e58ae0eb3d92df9fa5538349b6adf6448d15David BlaikieX0t<int> pr9789();
303e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smithtemplate<typename ...Types, // expected-error{{template parameter pack must be the last template parameter}}
313e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith         int After>
323e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smithusing A0t = int;
331ed64765624d6f5226dd213e220e038b459972d1Douglas Gregor
341ed64765624d6f5226dd213e220e038b459972d1Douglas Gregortemplate<int ...Values, // expected-error{{template parameter pack must be the last template parameter}}
351ed64765624d6f5226dd213e220e038b459972d1Douglas Gregor         int After>
361ed64765624d6f5226dd213e220e038b459972d1Douglas Gregorstruct X0nt;
373e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smithtemplate<int ...Values, // expected-error{{template parameter pack must be the last template parameter}}
383e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith         int After>
393e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smithusing A0nt = int;
401ed64765624d6f5226dd213e220e038b459972d1Douglas Gregor
411ed64765624d6f5226dd213e220e038b459972d1Douglas Gregortemplate<template<typename> class ...Templates, // expected-error{{template parameter pack must be the last template parameter}}
421ed64765624d6f5226dd213e220e038b459972d1Douglas Gregor         int After>
431ed64765624d6f5226dd213e220e038b459972d1Douglas Gregorstruct X0tt;
443e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smithtemplate<template<typename> class ...Templates, // expected-error{{template parameter pack must be the last template parameter}}
453e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith         int After>
463e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smithusing A0tt = int;
471ed64765624d6f5226dd213e220e038b459972d1Douglas Gregor
481ed64765624d6f5226dd213e220e038b459972d1Douglas Gregor// [ Note: These are not requirements for function templates or class
491ed64765624d6f5226dd213e220e038b459972d1Douglas Gregor// template partial specializations because template arguments can be
501ed64765624d6f5226dd213e220e038b459972d1Douglas Gregor// deduced (14.8.2). -- end note]
511ed64765624d6f5226dd213e220e038b459972d1Douglas Gregortemplate<typename... Types> struct X1t;
521ed64765624d6f5226dd213e220e038b459972d1Douglas Gregortemplate<typename ...Types, typename T> struct X1t<T, Types...> { };
531ed64765624d6f5226dd213e220e038b459972d1Douglas Gregor
541ed64765624d6f5226dd213e220e038b459972d1Douglas Gregortemplate<int... Values> struct X1nt;
551ed64765624d6f5226dd213e220e038b459972d1Douglas Gregortemplate<int ...Values, int V> struct X1nt<V, Values...> { };
561ed64765624d6f5226dd213e220e038b459972d1Douglas Gregor
57ba68eca7582a62e3e2ff4b0eba1b2b73a6b80895Douglas Gregortemplate<template<int> class... Meta> struct X1tt;
58ba68eca7582a62e3e2ff4b0eba1b2b73a6b80895Douglas Gregortemplate<template<int> class... Meta, template<int> class M>
59ba68eca7582a62e3e2ff4b0eba1b2b73a6b80895Douglas Gregor  struct X1tt<M, Meta...> { };
601ed64765624d6f5226dd213e220e038b459972d1Douglas Gregor
611ed64765624d6f5226dd213e220e038b459972d1Douglas Gregortemplate<typename ...Types, typename T>
621ed64765624d6f5226dd213e220e038b459972d1Douglas Gregorvoid f1t(X1t<T, Types...>);
631ed64765624d6f5226dd213e220e038b459972d1Douglas Gregor
641ed64765624d6f5226dd213e220e038b459972d1Douglas Gregortemplate<int ...Values, int V>
651ed64765624d6f5226dd213e220e038b459972d1Douglas Gregorvoid f1nt(X1nt<V, Values...>);
661ed64765624d6f5226dd213e220e038b459972d1Douglas Gregor
67ba68eca7582a62e3e2ff4b0eba1b2b73a6b80895Douglas Gregortemplate<template<int> class... Meta, template<int> class M>
68ba68eca7582a62e3e2ff4b0eba1b2b73a6b80895Douglas Gregorvoid f1tt(X1tt<M, Meta...>);
69ee5d21f63714459f39e0be28fec9dbecf0720505Douglas Gregor
70ee5d21f63714459f39e0be28fec9dbecf0720505Douglas Gregornamespace DefaultTemplateArgsInFunction {
71ee5d21f63714459f39e0be28fec9dbecf0720505Douglas Gregor  template<typename T = int, typename U>  T &f0(U) { T *x = 0; return *x; }
72ee5d21f63714459f39e0be28fec9dbecf0720505Douglas Gregor
73ee5d21f63714459f39e0be28fec9dbecf0720505Douglas Gregor  void test_f0() {
74ee5d21f63714459f39e0be28fec9dbecf0720505Douglas Gregor    int &ir0 = f0(3.14159);
75ee5d21f63714459f39e0be28fec9dbecf0720505Douglas Gregor    int &ir1 = f0<int>(3.14159);
76ee5d21f63714459f39e0be28fec9dbecf0720505Douglas Gregor    float &fr0 = f0<float>(3.14159);
77ee5d21f63714459f39e0be28fec9dbecf0720505Douglas Gregor  }
78ee5d21f63714459f39e0be28fec9dbecf0720505Douglas Gregor
79ee5d21f63714459f39e0be28fec9dbecf0720505Douglas Gregor  template<> int &f0(int*);
80ee5d21f63714459f39e0be28fec9dbecf0720505Douglas Gregor  template int &f0(double&);
81ee5d21f63714459f39e0be28fec9dbecf0720505Douglas Gregor}
82