1171dcdb092232e5561152c334ce6d2836be33f0cDouglas Gregor// RUN: %clang_cc1 -fsyntax-only -std=c++98 -Wconversion -verify %s
26ae5e6649f5d01a1b593f4db755bfcb42e095700Douglas Gregortemplate<int N> struct A; // expected-note 5{{template parameter is declared here}}
38b642592a35167a3780074e78674e0bece87c40cDouglas Gregor
48b642592a35167a3780074e78674e0bece87c40cDouglas GregorA<0> *a0;
58b642592a35167a3780074e78674e0bece87c40cDouglas Gregor
64b6ebe390fb0e38f6871d32db15cac29d22eb752Richard SmithA<int()> *a1; // expected-error{{template argument for non-type template parameter is treated as function type 'int ()'}}
78b642592a35167a3780074e78674e0bece87c40cDouglas Gregor
839a8de10c18365bde7062d8959b7ed525449c561Douglas GregorA<int> *a2; // expected-error{{template argument for non-type template parameter must be an expression}}
98b642592a35167a3780074e78674e0bece87c40cDouglas Gregor
10b3df1386680b3830d2f4d300d4d7eaba134135fcDouglas GregorA<1 >> 2> *a3; // expected-warning{{use of right-shift operator ('>>') in template argument will require parentheses in C++11}}
118b642592a35167a3780074e78674e0bece87c40cDouglas Gregor
126ae5e6649f5d01a1b593f4db755bfcb42e095700Douglas Gregor// C++ [temp.arg.nontype]p5:
13788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas GregorA<A> *a4; // expected-error{{must be an expression}}
146ae5e6649f5d01a1b593f4db755bfcb42e095700Douglas Gregor
156ae5e6649f5d01a1b593f4db755bfcb42e095700Douglas Gregorenum E { Enumerator = 17 };
1639a8de10c18365bde7062d8959b7ed525449c561Douglas GregorA<E> *a5; // expected-error{{template argument for non-type template parameter must be an expression}}
176ae5e6649f5d01a1b593f4db755bfcb42e095700Douglas Gregortemplate<E Value> struct A1; // expected-note{{template parameter is declared here}}
186ae5e6649f5d01a1b593f4db755bfcb42e095700Douglas GregorA1<Enumerator> *a6; // okay
197c2342dd4c9947806842e5aca3d2bb2e542853c9John McCallA1<17> *a7; // expected-error{{non-type template argument of type 'int' cannot be converted to a value of type 'E'}}
206ae5e6649f5d01a1b593f4db755bfcb42e095700Douglas Gregor
216ae5e6649f5d01a1b593f4db755bfcb42e095700Douglas Gregorconst long LongValue = 12345678;
226ae5e6649f5d01a1b593f4db755bfcb42e095700Douglas GregorA<LongValue> *a8;
236ae5e6649f5d01a1b593f4db755bfcb42e095700Douglas Gregorconst short ShortValue = 17;
246ae5e6649f5d01a1b593f4db755bfcb42e095700Douglas GregorA<ShortValue> *a9;
256ae5e6649f5d01a1b593f4db755bfcb42e095700Douglas Gregor
266ae5e6649f5d01a1b593f4db755bfcb42e095700Douglas Gregorint f(int);
2739a8de10c18365bde7062d8959b7ed525449c561Douglas GregorA<f(17)> *a10; // expected-error{{non-type template argument of type 'int' is not an integral constant expression}}
286ae5e6649f5d01a1b593f4db755bfcb42e095700Douglas Gregor
296ae5e6649f5d01a1b593f4db755bfcb42e095700Douglas Gregorclass X {
306ae5e6649f5d01a1b593f4db755bfcb42e095700Douglas Gregorpublic:
31a35284bba5db7a6179d70fcce8fbe66481058698Douglas Gregor  X();
326ae5e6649f5d01a1b593f4db755bfcb42e095700Douglas Gregor  X(int, int);
336ae5e6649f5d01a1b593f4db755bfcb42e095700Douglas Gregor  operator int() const;
346ae5e6649f5d01a1b593f4db755bfcb42e095700Douglas Gregor};
357c2342dd4c9947806842e5aca3d2bb2e542853c9John McCallA<X(17, 42)> *a11; // expected-error{{non-type template argument of type 'X' must have an integral or enumeration type}}
36a35284bba5db7a6179d70fcce8fbe66481058698Douglas Gregor
37a35284bba5db7a6179d70fcce8fbe66481058698Douglas Gregorfloat f(float);
38a35284bba5db7a6179d70fcce8fbe66481058698Douglas Gregor
391a8cf73a825ef35917eede448817237b5fd47b05Douglas Gregorfloat g(float); // expected-note 2{{candidate function}}
401a8cf73a825ef35917eede448817237b5fd47b05Douglas Gregordouble g(double); // expected-note 2{{candidate function}}
41a35284bba5db7a6179d70fcce8fbe66481058698Douglas Gregor
42a35284bba5db7a6179d70fcce8fbe66481058698Douglas Gregorint h(int);
43a35284bba5db7a6179d70fcce8fbe66481058698Douglas Gregorfloat h2(float);
44a35284bba5db7a6179d70fcce8fbe66481058698Douglas Gregor
451a8cf73a825ef35917eede448817237b5fd47b05Douglas Gregortemplate<int fp(int)> struct A3; // expected-note 1{{template parameter is declared here}}
46a35284bba5db7a6179d70fcce8fbe66481058698Douglas GregorA3<h> *a14_1;
47a35284bba5db7a6179d70fcce8fbe66481058698Douglas GregorA3<&h> *a14_2;
48a35284bba5db7a6179d70fcce8fbe66481058698Douglas GregorA3<f> *a14_3;
49a35284bba5db7a6179d70fcce8fbe66481058698Douglas GregorA3<&f> *a14_4;
50b7a09260204f2079e0f998bf7ee52b95122a4c5dDouglas GregorA3<h2> *a14_6;  // expected-error{{non-type template argument of type 'float (float)' cannot be converted to a value of type 'int (*)(int)'}}
511a8cf73a825ef35917eede448817237b5fd47b05Douglas GregorA3<g> *a14_7; // expected-error{{address of overloaded function 'g' does not match required type 'int (int)'}}
52f684e6e793a336f52138a2609b207e6eef3c3022Douglas Gregor
53f684e6e793a336f52138a2609b207e6eef3c3022Douglas Gregor
54f684e6e793a336f52138a2609b207e6eef3c3022Douglas Gregorstruct Y { } y;
55f684e6e793a336f52138a2609b207e6eef3c3022Douglas Gregor
56f684e6e793a336f52138a2609b207e6eef3c3022Douglas Gregorvolatile X * X_volatile_ptr;
57f684e6e793a336f52138a2609b207e6eef3c3022Douglas Gregortemplate<X const &AnX> struct A4; // expected-note 2{{template parameter is declared here}}
5886a7625062abbd40fffa186f2f5d305cc89615b8Douglas GregorX an_X;
59cc45cb3630b42c5245e26593e385097c220bc859Douglas GregorA4<an_X> *a15_1; // okay
60b7a09260204f2079e0f998bf7ee52b95122a4c5dDouglas GregorA4<*X_volatile_ptr> *a15_2; // expected-error{{non-type template argument does not refer to any declaration}}
610c42bb653dc40b1caae010618831e320af824b18Chris LattnerA4<y> *15_3; //  expected-error{{non-type template parameter of reference type 'const X &' cannot bind to template argument of type 'struct Y'}} \
6239a8de10c18365bde7062d8959b7ed525449c561Douglas Gregor            // FIXME: expected-error{{expected unqualified-id}}
63f684e6e793a336f52138a2609b207e6eef3c3022Douglas Gregor
641a8cf73a825ef35917eede448817237b5fd47b05Douglas Gregortemplate<int (&fr)(int)> struct A5; // expected-note{{template parameter is declared here}}
65b86b0579c5805c8ecaedd2d676e06bf8c2bf7f79Douglas GregorA5<h> *a16_1;
66b86b0579c5805c8ecaedd2d676e06bf8c2bf7f79Douglas GregorA5<f> *a16_3;
67b7a09260204f2079e0f998bf7ee52b95122a4c5dDouglas GregorA5<h2> *a16_6;  // expected-error{{non-type template parameter of reference type 'int (&)(int)' cannot bind to template argument of type 'float (float)'}}
681a8cf73a825ef35917eede448817237b5fd47b05Douglas GregorA5<g> *a14_7; // expected-error{{address of overloaded function 'g' does not match required type 'int (int)'}}
69b86b0579c5805c8ecaedd2d676e06bf8c2bf7f79Douglas Gregor
70b86b0579c5805c8ecaedd2d676e06bf8c2bf7f79Douglas Gregorstruct Z {
71b86b0579c5805c8ecaedd2d676e06bf8c2bf7f79Douglas Gregor  int foo(int);
72b86b0579c5805c8ecaedd2d676e06bf8c2bf7f79Douglas Gregor  float bar(float);
73b86b0579c5805c8ecaedd2d676e06bf8c2bf7f79Douglas Gregor  int bar(int);
74b86b0579c5805c8ecaedd2d676e06bf8c2bf7f79Douglas Gregor  double baz(double);
75658bbb5e8072ccd68b5ddc299d1b868aa047a746Douglas Gregor
76658bbb5e8072ccd68b5ddc299d1b868aa047a746Douglas Gregor  int int_member;
77658bbb5e8072ccd68b5ddc299d1b868aa047a746Douglas Gregor  float float_member;
78255ca71082810ac8d3084f43727675e02a384683David Majnemer  union {
79255ca71082810ac8d3084f43727675e02a384683David Majnemer    int union_member;
80255ca71082810ac8d3084f43727675e02a384683David Majnemer  };
81b86b0579c5805c8ecaedd2d676e06bf8c2bf7f79Douglas Gregor};
82b86b0579c5805c8ecaedd2d676e06bf8c2bf7f79Douglas Gregortemplate<int (Z::*pmf)(int)> struct A6; // expected-note{{template parameter is declared here}}
83b86b0579c5805c8ecaedd2d676e06bf8c2bf7f79Douglas GregorA6<&Z::foo> *a17_1;
84b86b0579c5805c8ecaedd2d676e06bf8c2bf7f79Douglas GregorA6<&Z::bar> *a17_2;
85651f13cea278ec967336033dd032faef0e9fc2ecStephen HinesA6<&Z::baz> *a17_3; // expected-error-re{{non-type template argument of type 'double (Z::*)(double){{( __attribute__\(\(thiscall\)\))?}}' cannot be converted to a value of type 'int (Z::*)(int){{( __attribute__\(\(thiscall\)\))?}}'}}
86658bbb5e8072ccd68b5ddc299d1b868aa047a746Douglas Gregor
87658bbb5e8072ccd68b5ddc299d1b868aa047a746Douglas Gregor
88658bbb5e8072ccd68b5ddc299d1b868aa047a746Douglas Gregortemplate<int Z::*pm> struct A7;  // expected-note{{template parameter is declared here}}
89658bbb5e8072ccd68b5ddc299d1b868aa047a746Douglas Gregortemplate<int Z::*pm> struct A7c;
90658bbb5e8072ccd68b5ddc299d1b868aa047a746Douglas GregorA7<&Z::int_member> *a18_1;
91658bbb5e8072ccd68b5ddc299d1b868aa047a746Douglas GregorA7c<&Z::int_member> *a18_2;
927c2342dd4c9947806842e5aca3d2bb2e542853c9John McCallA7<&Z::float_member> *a18_3; // expected-error{{non-type template argument of type 'float Z::*' cannot be converted to a value of type 'int Z::*'}}
932c5399f99c95b831fa90fd3a3c1d9719c1dd9441Abramo BagnaraA7c<(&Z::int_member)> *a18_4; // expected-warning{{address non-type template argument cannot be surrounded by parentheses}}
94255ca71082810ac8d3084f43727675e02a384683David MajnemerA7c<&Z::union_member> *a18_5;
95f80a9d5c2ccc465211178223799217f7a42774aeDouglas Gregor
96f80a9d5c2ccc465211178223799217f7a42774aeDouglas Gregortemplate<unsigned char C> struct Overflow; // expected-note{{template parameter is declared here}}
97f80a9d5c2ccc465211178223799217f7a42774aeDouglas Gregor
98f80a9d5c2ccc465211178223799217f7a42774aeDouglas GregorOverflow<5> *overflow1; // okay
9929f89f6be93b2f5c7a2b43877cf2555d03aa92a6Eli FriedmanOverflow<255> *overflow2; // okay
1001a6e03457ebafd6ac523cdcf5d6b6f411ea08772Douglas GregorOverflow<256> *overflow3; // expected-warning{{non-type template argument value '256' truncated to '0' for template parameter of type 'unsigned char'}}
101f80a9d5c2ccc465211178223799217f7a42774aeDouglas Gregor
102f80a9d5c2ccc465211178223799217f7a42774aeDouglas Gregor
103f80a9d5c2ccc465211178223799217f7a42774aeDouglas Gregortemplate<unsigned> struct Signedness; // expected-note{{template parameter is declared here}}
104f80a9d5c2ccc465211178223799217f7a42774aeDouglas GregorSignedness<10> *signedness1; // okay
1051a6e03457ebafd6ac523cdcf5d6b6f411ea08772Douglas GregorSignedness<-10> *signedness2; // expected-warning{{non-type template argument with value '-10' converted to '4294967286' for unsigned template parameter of type 'unsigned int'}}
106040867836278659d02baa18e044bd996155ec3b5Douglas Gregor
10729f89f6be93b2f5c7a2b43877cf2555d03aa92a6Eli Friedmantemplate<signed char C> struct SignedOverflow; // expected-note 3 {{template parameter is declared here}}
10829f89f6be93b2f5c7a2b43877cf2555d03aa92a6Eli FriedmanSignedOverflow<1> *signedoverflow1;
10929f89f6be93b2f5c7a2b43877cf2555d03aa92a6Eli FriedmanSignedOverflow<-1> *signedoverflow2;
11029f89f6be93b2f5c7a2b43877cf2555d03aa92a6Eli FriedmanSignedOverflow<-128> *signedoverflow3;
1111a6e03457ebafd6ac523cdcf5d6b6f411ea08772Douglas GregorSignedOverflow<-129> *signedoverflow4; // expected-warning{{non-type template argument value '-129' truncated to '127' for template parameter of type 'signed char'}}
11229f89f6be93b2f5c7a2b43877cf2555d03aa92a6Eli FriedmanSignedOverflow<127> *signedoverflow5;
1131a6e03457ebafd6ac523cdcf5d6b6f411ea08772Douglas GregorSignedOverflow<128> *signedoverflow6; // expected-warning{{non-type template argument value '128' truncated to '-128' for template parameter of type 'signed char'}}
1141a6e03457ebafd6ac523cdcf5d6b6f411ea08772Douglas GregorSignedOverflow<(unsigned char)128> *signedoverflow7; // expected-warning{{non-type template argument value '128' truncated to '-128' for template parameter of type 'signed char'}}
11529f89f6be93b2f5c7a2b43877cf2555d03aa92a6Eli Friedman
116040867836278659d02baa18e044bd996155ec3b5Douglas Gregor// Check canonicalization of template arguments.
117040867836278659d02baa18e044bd996155ec3b5Douglas Gregortemplate<int (*)(int, int)> struct FuncPtr0;
118040867836278659d02baa18e044bd996155ec3b5Douglas Gregorint func0(int, int);
119040867836278659d02baa18e044bd996155ec3b5Douglas Gregorextern FuncPtr0<&func0> *fp0;
120040867836278659d02baa18e044bd996155ec3b5Douglas Gregortemplate<int (*)(int, int)> struct FuncPtr0;
121040867836278659d02baa18e044bd996155ec3b5Douglas Gregorextern FuncPtr0<&func0> *fp0;
122040867836278659d02baa18e044bd996155ec3b5Douglas Gregorint func0(int, int);
123040867836278659d02baa18e044bd996155ec3b5Douglas Gregorextern FuncPtr0<&func0> *fp0;
124040867836278659d02baa18e044bd996155ec3b5Douglas Gregor
125862354188764f4a20be21d103bc2abd074ad048aDouglas Gregor// PR5350
126862354188764f4a20be21d103bc2abd074ad048aDouglas Gregornamespace ns {
127862354188764f4a20be21d103bc2abd074ad048aDouglas Gregor  template <typename T>
128862354188764f4a20be21d103bc2abd074ad048aDouglas Gregor  struct Foo {
129862354188764f4a20be21d103bc2abd074ad048aDouglas Gregor    static const bool value = true;
130862354188764f4a20be21d103bc2abd074ad048aDouglas Gregor  };
131862354188764f4a20be21d103bc2abd074ad048aDouglas Gregor
132862354188764f4a20be21d103bc2abd074ad048aDouglas Gregor  template <bool b>
133862354188764f4a20be21d103bc2abd074ad048aDouglas Gregor  struct Bar {};
134862354188764f4a20be21d103bc2abd074ad048aDouglas Gregor
135862354188764f4a20be21d103bc2abd074ad048aDouglas Gregor  const bool value = false;
136862354188764f4a20be21d103bc2abd074ad048aDouglas Gregor
137862354188764f4a20be21d103bc2abd074ad048aDouglas Gregor  Bar<bool(ns::Foo<int>::value)> x;
138862354188764f4a20be21d103bc2abd074ad048aDouglas Gregor}
139ff5243981e2f6fb4a11ab7b81bf7accc226f2647Douglas Gregor
140ff5243981e2f6fb4a11ab7b81bf7accc226f2647Douglas Gregor// PR5349
141ff5243981e2f6fb4a11ab7b81bf7accc226f2647Douglas Gregornamespace ns {
142ff5243981e2f6fb4a11ab7b81bf7accc226f2647Douglas Gregor  enum E { k };
143ff5243981e2f6fb4a11ab7b81bf7accc226f2647Douglas Gregor
144ff5243981e2f6fb4a11ab7b81bf7accc226f2647Douglas Gregor  template <E e>
145ff5243981e2f6fb4a11ab7b81bf7accc226f2647Douglas Gregor  struct Baz  {};
146ff5243981e2f6fb4a11ab7b81bf7accc226f2647Douglas Gregor
147ff5243981e2f6fb4a11ab7b81bf7accc226f2647Douglas Gregor  Baz<k> f1;  // This works.
148ff5243981e2f6fb4a11ab7b81bf7accc226f2647Douglas Gregor  Baz<E(0)> f2;  // This too.
149ff5243981e2f6fb4a11ab7b81bf7accc226f2647Douglas Gregor  Baz<static_cast<E>(0)> f3;  // And this.
150ff5243981e2f6fb4a11ab7b81bf7accc226f2647Douglas Gregor
151ff5243981e2f6fb4a11ab7b81bf7accc226f2647Douglas Gregor  Baz<ns::E(0)> b1;  // This doesn't work.
152ff5243981e2f6fb4a11ab7b81bf7accc226f2647Douglas Gregor  Baz<static_cast<ns::E>(0)> b2;  // This neither.
153ff5243981e2f6fb4a11ab7b81bf7accc226f2647Douglas Gregor}
154ff5243981e2f6fb4a11ab7b81bf7accc226f2647Douglas Gregor
155d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor// PR5597
156d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregortemplate<int (*)(float)> struct X0 { };
157d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor
158d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregorstruct X1 {
159d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor    static int pfunc(float);
160d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor};
161d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregorvoid test_X0_X1() {
162d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor  X0<X1::pfunc> x01;
163d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor}
164645cf44cc34371c808743e5e7c19bb41ff593ca0John McCall
165645cf44cc34371c808743e5e7c19bb41ff593ca0John McCall// PR6249
166645cf44cc34371c808743e5e7c19bb41ff593ca0John McCallnamespace pr6249 {
167645cf44cc34371c808743e5e7c19bb41ff593ca0John McCall  template<typename T, T (*func)()> T f() {
168645cf44cc34371c808743e5e7c19bb41ff593ca0John McCall    return func();
169645cf44cc34371c808743e5e7c19bb41ff593ca0John McCall  }
170645cf44cc34371c808743e5e7c19bb41ff593ca0John McCall
171645cf44cc34371c808743e5e7c19bb41ff593ca0John McCall  int h();
172645cf44cc34371c808743e5e7c19bb41ff593ca0John McCall  template int f<int, h>();
173645cf44cc34371c808743e5e7c19bb41ff593ca0John McCall}
17402024a9f0d8e6c898de276193af604c42ee41269Douglas Gregor
17502024a9f0d8e6c898de276193af604c42ee41269Douglas Gregornamespace PR6723 {
176a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor  template<unsigned char C> void f(int (&a)[C]); // expected-note {{candidate template ignored}} \
1775fad9b8362c62e230f6603d86ec7d1747e74c737Douglas Gregor  // expected-note{{substitution failure [with C = '\x00']}}
17802024a9f0d8e6c898de276193af604c42ee41269Douglas Gregor  void g() {
17902024a9f0d8e6c898de276193af604c42ee41269Douglas Gregor    int arr512[512];
18002024a9f0d8e6c898de276193af604c42ee41269Douglas Gregor    f(arr512); // expected-error{{no matching function for call}}
18102024a9f0d8e6c898de276193af604c42ee41269Douglas Gregor    f<512>(arr512); // expected-error{{no matching function for call}}
18202024a9f0d8e6c898de276193af604c42ee41269Douglas Gregor  }
18302024a9f0d8e6c898de276193af604c42ee41269Douglas Gregor}
18477c13e07314422c6e76eda1bd1c7d83181b7e526Douglas Gregor
18577c13e07314422c6e76eda1bd1c7d83181b7e526Douglas Gregor// Check that we instantiate declarations whose addresses are taken
18677c13e07314422c6e76eda1bd1c7d83181b7e526Douglas Gregor// for non-type template arguments.
18777c13e07314422c6e76eda1bd1c7d83181b7e526Douglas Gregornamespace EntityReferenced {
18877c13e07314422c6e76eda1bd1c7d83181b7e526Douglas Gregor  template<typename T, void (*)(T)> struct X { };
18977c13e07314422c6e76eda1bd1c7d83181b7e526Douglas Gregor
19077c13e07314422c6e76eda1bd1c7d83181b7e526Douglas Gregor  template<typename T>
19177c13e07314422c6e76eda1bd1c7d83181b7e526Douglas Gregor  struct Y {
19277c13e07314422c6e76eda1bd1c7d83181b7e526Douglas Gregor    static void f(T x) {
19377c13e07314422c6e76eda1bd1c7d83181b7e526Douglas Gregor      x = 1; // expected-error{{assigning to 'int *' from incompatible type 'int'}}
19477c13e07314422c6e76eda1bd1c7d83181b7e526Douglas Gregor    }
19577c13e07314422c6e76eda1bd1c7d83181b7e526Douglas Gregor  };
19677c13e07314422c6e76eda1bd1c7d83181b7e526Douglas Gregor
19777c13e07314422c6e76eda1bd1c7d83181b7e526Douglas Gregor  void g() {
19877c13e07314422c6e76eda1bd1c7d83181b7e526Douglas Gregor    typedef X<int*, Y<int*>::f> x; // expected-note{{in instantiation of}}
19977c13e07314422c6e76eda1bd1c7d83181b7e526Douglas Gregor  }
20077c13e07314422c6e76eda1bd1c7d83181b7e526Douglas Gregor}
20177e2c67411084c47b1cf511a191b31adf38662baDouglas Gregor
20277e2c67411084c47b1cf511a191b31adf38662baDouglas Gregornamespace PR6964 {
20377e2c67411084c47b1cf511a191b31adf38662baDouglas Gregor  template <typename ,int, int = 9223372036854775807L > // expected-warning 2{{non-type template argument value '9223372036854775807' truncated to '-1' for template parameter of type 'int'}} \
20477e2c67411084c47b1cf511a191b31adf38662baDouglas Gregor  // expected-note 2{{template parameter is declared here}}
20577e2c67411084c47b1cf511a191b31adf38662baDouglas Gregor  struct as_nview { };
20677e2c67411084c47b1cf511a191b31adf38662baDouglas Gregor
20777e2c67411084c47b1cf511a191b31adf38662baDouglas Gregor  template <typename Sequence, int I0>
20877e2c67411084c47b1cf511a191b31adf38662baDouglas Gregor  struct as_nview<Sequence, I0>  // expected-note{{while checking a default template argument used here}}
20977e2c67411084c47b1cf511a191b31adf38662baDouglas Gregor  { };
21077e2c67411084c47b1cf511a191b31adf38662baDouglas Gregor}
211766724566289e6951a90b6483f0d3e22fe4b9b52John McCall
212766724566289e6951a90b6483f0d3e22fe4b9b52John McCall// rdar://problem/8302138
213766724566289e6951a90b6483f0d3e22fe4b9b52John McCallnamespace test8 {
214766724566289e6951a90b6483f0d3e22fe4b9b52John McCall  template <int* ip> struct A {
215766724566289e6951a90b6483f0d3e22fe4b9b52John McCall    int* p;
216766724566289e6951a90b6483f0d3e22fe4b9b52John McCall    A() : p(ip) {}
217766724566289e6951a90b6483f0d3e22fe4b9b52John McCall  };
218766724566289e6951a90b6483f0d3e22fe4b9b52John McCall
219766724566289e6951a90b6483f0d3e22fe4b9b52John McCall  void test0() {
220766724566289e6951a90b6483f0d3e22fe4b9b52John McCall    extern int i00;
221766724566289e6951a90b6483f0d3e22fe4b9b52John McCall    A<&i00> a00;
222766724566289e6951a90b6483f0d3e22fe4b9b52John McCall  }
223766724566289e6951a90b6483f0d3e22fe4b9b52John McCall
224766724566289e6951a90b6483f0d3e22fe4b9b52John McCall  extern int i01;
225766724566289e6951a90b6483f0d3e22fe4b9b52John McCall  void test1() {
226766724566289e6951a90b6483f0d3e22fe4b9b52John McCall    A<&i01> a01;
227766724566289e6951a90b6483f0d3e22fe4b9b52John McCall  }
228766724566289e6951a90b6483f0d3e22fe4b9b52John McCall
229766724566289e6951a90b6483f0d3e22fe4b9b52John McCall
230766724566289e6951a90b6483f0d3e22fe4b9b52John McCall  struct C {
231766724566289e6951a90b6483f0d3e22fe4b9b52John McCall    int x;
232766724566289e6951a90b6483f0d3e22fe4b9b52John McCall    char y;
233766724566289e6951a90b6483f0d3e22fe4b9b52John McCall    double z;
234766724566289e6951a90b6483f0d3e22fe4b9b52John McCall  };
235766724566289e6951a90b6483f0d3e22fe4b9b52John McCall
236766724566289e6951a90b6483f0d3e22fe4b9b52John McCall  template <C* cp> struct B {
237766724566289e6951a90b6483f0d3e22fe4b9b52John McCall    C* p;
238766724566289e6951a90b6483f0d3e22fe4b9b52John McCall    B() : p(cp) {}
239766724566289e6951a90b6483f0d3e22fe4b9b52John McCall  };
240766724566289e6951a90b6483f0d3e22fe4b9b52John McCall
241766724566289e6951a90b6483f0d3e22fe4b9b52John McCall  void test2() {
242766724566289e6951a90b6483f0d3e22fe4b9b52John McCall    extern C c02;
243766724566289e6951a90b6483f0d3e22fe4b9b52John McCall    B<&c02> b02;
244766724566289e6951a90b6483f0d3e22fe4b9b52John McCall  }
245766724566289e6951a90b6483f0d3e22fe4b9b52John McCall
246766724566289e6951a90b6483f0d3e22fe4b9b52John McCall  extern C c03;
247766724566289e6951a90b6483f0d3e22fe4b9b52John McCall  void test3() {
248766724566289e6951a90b6483f0d3e22fe4b9b52John McCall    B<&c03> b03;
249766724566289e6951a90b6483f0d3e22fe4b9b52John McCall  }
250766724566289e6951a90b6483f0d3e22fe4b9b52John McCall}
251b535041ee33c5eff255832bc5541c8d52aae8254Douglas Gregor
252b535041ee33c5eff255832bc5541c8d52aae8254Douglas Gregornamespace PR8372 {
253b535041ee33c5eff255832bc5541c8d52aae8254Douglas Gregor  template <int I> void foo() { } // expected-note{{template parameter is declared here}}
254b535041ee33c5eff255832bc5541c8d52aae8254Douglas Gregor  void bar() { foo <0x80000000> (); } // expected-warning{{non-type template argument value '2147483648' truncated to '-2147483648' for template parameter of type 'int'}}
255b535041ee33c5eff255832bc5541c8d52aae8254Douglas Gregor}
256781701c3d34740c53ad912ad007383ae2951c637Chandler Carruth
257781701c3d34740c53ad912ad007383ae2951c637Chandler Carruthnamespace PR9227 {
258781701c3d34740c53ad912ad007383ae2951c637Chandler Carruth  template <bool B> struct enable_if_bool { };
259b5c7768a74936d4e2c7a484570a638cb74702d8bKaelyn Uhrain  template <> struct enable_if_bool<true> { typedef int type; }; // expected-note{{'enable_if_bool<true>::type' declared here}}
260b5c7768a74936d4e2c7a484570a638cb74702d8bKaelyn Uhrain  void test_bool() { enable_if_bool<false>::type i; } // expected-error{{enable_if_bool<false>'; did you mean 'enable_if_bool<true>::type'?}}
261781701c3d34740c53ad912ad007383ae2951c637Chandler Carruth
262781701c3d34740c53ad912ad007383ae2951c637Chandler Carruth  template <char C> struct enable_if_char { };
263b5c7768a74936d4e2c7a484570a638cb74702d8bKaelyn Uhrain  template <> struct enable_if_char<'a'> { typedef int type; }; // expected-note 5{{'enable_if_char<'a'>::type' declared here}}
264b5c7768a74936d4e2c7a484570a638cb74702d8bKaelyn Uhrain  void test_char_0() { enable_if_char<0>::type i; } // expected-error{{enable_if_char<'\x00'>'; did you mean 'enable_if_char<'a'>::type'?}}
265b5c7768a74936d4e2c7a484570a638cb74702d8bKaelyn Uhrain  void test_char_b() { enable_if_char<'b'>::type i; } // expected-error{{enable_if_char<'b'>'; did you mean 'enable_if_char<'a'>::type'?}}
266b5c7768a74936d4e2c7a484570a638cb74702d8bKaelyn Uhrain  void test_char_possibly_negative() { enable_if_char<'\x02'>::type i; } // expected-error{{enable_if_char<'\x02'>'; did you mean 'enable_if_char<'a'>::type'?}}
267b5c7768a74936d4e2c7a484570a638cb74702d8bKaelyn Uhrain  void test_char_single_quote() { enable_if_char<'\''>::type i; } // expected-error{{enable_if_char<'\''>'; did you mean 'enable_if_char<'a'>::type'?}}
268b5c7768a74936d4e2c7a484570a638cb74702d8bKaelyn Uhrain  void test_char_backslash() { enable_if_char<'\\'>::type i; } // expected-error{{enable_if_char<'\\'>'; did you mean 'enable_if_char<'a'>::type'?}}
269781701c3d34740c53ad912ad007383ae2951c637Chandler Carruth}
2706b63f551b183e14fab6ac51d6e5199c90b699035Douglas Gregor
2716b63f551b183e14fab6ac51d6e5199c90b699035Douglas Gregornamespace PR10579 {
2726b63f551b183e14fab6ac51d6e5199c90b699035Douglas Gregor  namespace fcppt
2736b63f551b183e14fab6ac51d6e5199c90b699035Douglas Gregor  {
2746b63f551b183e14fab6ac51d6e5199c90b699035Douglas Gregor    namespace container
2756b63f551b183e14fab6ac51d6e5199c90b699035Douglas Gregor    {
2766b63f551b183e14fab6ac51d6e5199c90b699035Douglas Gregor      namespace bitfield
2776b63f551b183e14fab6ac51d6e5199c90b699035Douglas Gregor      {
2786b63f551b183e14fab6ac51d6e5199c90b699035Douglas Gregor
2796b63f551b183e14fab6ac51d6e5199c90b699035Douglas Gregor        template<
2806b63f551b183e14fab6ac51d6e5199c90b699035Douglas Gregor          typename Enum,
2816b63f551b183e14fab6ac51d6e5199c90b699035Douglas Gregor          Enum Size
2826b63f551b183e14fab6ac51d6e5199c90b699035Douglas Gregor          >
2836b63f551b183e14fab6ac51d6e5199c90b699035Douglas Gregor        class basic;
2846b63f551b183e14fab6ac51d6e5199c90b699035Douglas Gregor
2856b63f551b183e14fab6ac51d6e5199c90b699035Douglas Gregor        template<
2866b63f551b183e14fab6ac51d6e5199c90b699035Douglas Gregor          typename Enum,
2876b63f551b183e14fab6ac51d6e5199c90b699035Douglas Gregor          Enum Size
2886b63f551b183e14fab6ac51d6e5199c90b699035Douglas Gregor          >
2896b63f551b183e14fab6ac51d6e5199c90b699035Douglas Gregor        class basic
2906b63f551b183e14fab6ac51d6e5199c90b699035Douglas Gregor        {
2916b63f551b183e14fab6ac51d6e5199c90b699035Douglas Gregor        public:
2926b63f551b183e14fab6ac51d6e5199c90b699035Douglas Gregor          basic()
2936b63f551b183e14fab6ac51d6e5199c90b699035Douglas Gregor          {
2946b63f551b183e14fab6ac51d6e5199c90b699035Douglas Gregor          }
2956b63f551b183e14fab6ac51d6e5199c90b699035Douglas Gregor        };
2966b63f551b183e14fab6ac51d6e5199c90b699035Douglas Gregor
2976b63f551b183e14fab6ac51d6e5199c90b699035Douglas Gregor      }
2986b63f551b183e14fab6ac51d6e5199c90b699035Douglas Gregor    }
2996b63f551b183e14fab6ac51d6e5199c90b699035Douglas Gregor  }
3006b63f551b183e14fab6ac51d6e5199c90b699035Douglas Gregor
3016b63f551b183e14fab6ac51d6e5199c90b699035Douglas Gregor  namespace
3026b63f551b183e14fab6ac51d6e5199c90b699035Douglas Gregor  {
3036b63f551b183e14fab6ac51d6e5199c90b699035Douglas Gregor
3046b63f551b183e14fab6ac51d6e5199c90b699035Douglas Gregor    namespace testenum
3056b63f551b183e14fab6ac51d6e5199c90b699035Douglas Gregor    {
3066b63f551b183e14fab6ac51d6e5199c90b699035Douglas Gregor      enum type
3076b63f551b183e14fab6ac51d6e5199c90b699035Douglas Gregor        {
3086b63f551b183e14fab6ac51d6e5199c90b699035Douglas Gregor          foo,
3096b63f551b183e14fab6ac51d6e5199c90b699035Douglas Gregor          bar,
3106b63f551b183e14fab6ac51d6e5199c90b699035Douglas Gregor          size
3116b63f551b183e14fab6ac51d6e5199c90b699035Douglas Gregor        };
3126b63f551b183e14fab6ac51d6e5199c90b699035Douglas Gregor    }
3136b63f551b183e14fab6ac51d6e5199c90b699035Douglas Gregor
3146b63f551b183e14fab6ac51d6e5199c90b699035Douglas Gregor  }
3156b63f551b183e14fab6ac51d6e5199c90b699035Douglas Gregor
3166b63f551b183e14fab6ac51d6e5199c90b699035Douglas Gregor  int main()
3176b63f551b183e14fab6ac51d6e5199c90b699035Douglas Gregor  {
3186b63f551b183e14fab6ac51d6e5199c90b699035Douglas Gregor    typedef fcppt::container::bitfield::basic<
3196b63f551b183e14fab6ac51d6e5199c90b699035Douglas Gregor    testenum::type,
3206b63f551b183e14fab6ac51d6e5199c90b699035Douglas Gregor      testenum::size
3216b63f551b183e14fab6ac51d6e5199c90b699035Douglas Gregor      > bitfield_foo;
3226b63f551b183e14fab6ac51d6e5199c90b699035Douglas Gregor
3236b63f551b183e14fab6ac51d6e5199c90b699035Douglas Gregor    bitfield_foo obj;
3246b63f551b183e14fab6ac51d6e5199c90b699035Douglas Gregor  }
3256b63f551b183e14fab6ac51d6e5199c90b699035Douglas Gregor
3266b63f551b183e14fab6ac51d6e5199c90b699035Douglas Gregor}
3277b2f51c758a14205f4c4215d7dc04a4cf3947b8aEli Friedman
3287b2f51c758a14205f4c4215d7dc04a4cf3947b8aEli Friedmantemplate <int& I> struct PR10766 { static int *ip; };
3297b2f51c758a14205f4c4215d7dc04a4cf3947b8aEli Friedmantemplate <int& I> int* PR10766<I>::ip = &I;
330b9df75f1b83d36be7bfbafc2f25d9fcf768874a3Douglas Gregor
331b9df75f1b83d36be7bfbafc2f25d9fcf768874a3Douglas Gregornamespace rdar13000548 {
33298b879af5bfb50123a668dc1de6dd86feb9991c5David Blaikie  template<typename R, typename U, R F>
33398b879af5bfb50123a668dc1de6dd86feb9991c5David Blaikie  U f() { return &F; } // expected-error{{cannot take the address of an rvalue of type 'int (*)(int)'}} expected-error{{cannot take the address of an rvalue of type 'int *'}}
334b9df75f1b83d36be7bfbafc2f25d9fcf768874a3Douglas Gregor
335b9df75f1b83d36be7bfbafc2f25d9fcf768874a3Douglas Gregor  int g(int);
33698b879af5bfb50123a668dc1de6dd86feb9991c5David Blaikie  int y[3];
337b9df75f1b83d36be7bfbafc2f25d9fcf768874a3Douglas Gregor  void test()
338b9df75f1b83d36be7bfbafc2f25d9fcf768874a3Douglas Gregor  {
33998b879af5bfb50123a668dc1de6dd86feb9991c5David Blaikie    f<int(int), int (*)(int), g>(); // expected-note{{in instantiation of}}
34098b879af5bfb50123a668dc1de6dd86feb9991c5David Blaikie    f<int[3], int*, y>(); // expected-note{{in instantiation of}}
341b9df75f1b83d36be7bfbafc2f25d9fcf768874a3Douglas Gregor  }
342b9df75f1b83d36be7bfbafc2f25d9fcf768874a3Douglas Gregor
343b9df75f1b83d36be7bfbafc2f25d9fcf768874a3Douglas Gregor}
34479bef7aea4419b75e2cca0f121c6e1a4232bb03cDouglas Gregor
34579bef7aea4419b75e2cca0f121c6e1a4232bb03cDouglas Gregornamespace rdar13806270 {
34679bef7aea4419b75e2cca0f121c6e1a4232bb03cDouglas Gregor  template <unsigned N> class X { };
34779bef7aea4419b75e2cca0f121c6e1a4232bb03cDouglas Gregor  const unsigned value = 32;
34879bef7aea4419b75e2cca0f121c6e1a4232bb03cDouglas Gregor  struct Y {
34979bef7aea4419b75e2cca0f121c6e1a4232bb03cDouglas Gregor    X<value + 1> x;
35079bef7aea4419b75e2cca0f121c6e1a4232bb03cDouglas Gregor  };
35179bef7aea4419b75e2cca0f121c6e1a4232bb03cDouglas Gregor  void foo() {}
35279bef7aea4419b75e2cca0f121c6e1a4232bb03cDouglas Gregor}
353d7b485599cf23605e0e7e9846a7c5df11783b9f7David Majnemer
354d7b485599cf23605e0e7e9846a7c5df11783b9f7David Majnemernamespace PR17696 {
355d7b485599cf23605e0e7e9846a7c5df11783b9f7David Majnemer  struct a {
356d7b485599cf23605e0e7e9846a7c5df11783b9f7David Majnemer    union {
357d7b485599cf23605e0e7e9846a7c5df11783b9f7David Majnemer      int i;
358d7b485599cf23605e0e7e9846a7c5df11783b9f7David Majnemer    };
359d7b485599cf23605e0e7e9846a7c5df11783b9f7David Majnemer  };
360d7b485599cf23605e0e7e9846a7c5df11783b9f7David Majnemer
361d7b485599cf23605e0e7e9846a7c5df11783b9f7David Majnemer  template <int (a::*p)> struct b : a {
362d7b485599cf23605e0e7e9846a7c5df11783b9f7David Majnemer    b() { this->*p = 0; }
363d7b485599cf23605e0e7e9846a7c5df11783b9f7David Majnemer  };
364d7b485599cf23605e0e7e9846a7c5df11783b9f7David Majnemer
365d7b485599cf23605e0e7e9846a7c5df11783b9f7David Majnemer  b<&a::i> c; // okay
366d7b485599cf23605e0e7e9846a7c5df11783b9f7David Majnemer}
367