1 // RUN: %clang_cc1 -std=c++11 %s -verify -triple x86_64-linux-gnu
2 
3 namespace std {
4   typedef decltype(nullptr) nullptr_t;
5 }
6 
7 template<int *ip> struct IP {  // expected-note 5 {{template parameter is declared here}}
8   IP<ip> *ip2;
9 };
10 
11 template<int &ip> struct IR {};
12 
13 constexpr std::nullptr_t get_nullptr() { return nullptr; }
14 
15 constexpr std::nullptr_t np = nullptr;
16 
17 std::nullptr_t nonconst_np; // expected-note{{declared here}}
18 
19 thread_local int tl; // expected-note {{refers here}}
20 
21 IP<0> ip0; // expected-error{{null non-type template argument must be cast to template parameter type 'int *'}}
22 IP<(0)> ip1; // expected-error{{null non-type template argument must be cast to template parameter type 'int *'}}
23 IP<nullptr> ip2;
24 IP<get_nullptr()> ip3;
25 IP<(int*)0> ip4;
26 IP<np> ip5;
27 IP<nonconst_np> ip5; // expected-error{{non-type template argument of type 'std::nullptr_t' (aka 'nullptr_t') is not a constant expression}} \
28 // expected-note{{read of non-constexpr variable 'nonconst_np' is not allowed in a constant expression}}
29 IP<(float*)0> ip6; // expected-error{{null non-type template argument of type 'float *' does not match template parameter of type 'int *'}}
30 IP<&tl> ip7; // expected-error{{non-type template argument of type 'int *' is not a constant expression}}
31 
32 IR<tl> ir1; // expected-error{{non-type template argument refers to thread-local object}}
33 
34 struct X { };
35 template<int X::*pm> struct PM { // expected-note 2 {{template parameter is declared here}}
36   PM<pm> *pm2;
37 };
38 
39 PM<0> pm0; // expected-error{{null non-type template argument must be cast to template parameter type 'int X::*'}}
40 PM<(0)> pm1; // expected-error{{null non-type template argument must be cast to template parameter type 'int X::*'}}
41 PM<nullptr> pm2;
42 PM<get_nullptr()> pm3;
43 PM<(int X::*)0> pm4;
44 PM<np> pm5;
45 
46 template<int (X::*pmf)(int)> struct PMF { // expected-note 2 {{template parameter is declared here}}
47   PMF<pmf> *pmf2;
48 };
49 
50 PMF<0> pmf0; // expected-error{{null non-type template argument must be cast to template parameter type 'int (X::*)(int)'}}
51 PMF<(0)> pmf1; // expected-error{{null non-type template argument must be cast to template parameter type 'int (X::*)(int)'}}
52 PMF<nullptr> pmf2;
53 PMF<get_nullptr()> pmf3;
54 PMF<(int (X::*)(int))0> pmf4;
55 PMF<np> pmf5;
56 
57 
58 template<std::nullptr_t np> struct NP { // expected-note 2{{template parameter is declared here}}
59   NP<np> *np2;
60 };
61 
62 NP<nullptr> np1;
63 NP<np> np2;
64 NP<get_nullptr()> np3;
65 NP<0> np4; // expected-error{{null non-type template argument must be cast to template parameter type 'std::nullptr_t' (aka 'nullptr_t')}}
66 constexpr int i = 7;
67 NP<i> np5; // expected-error{{non-type template argument of type 'const int' cannot be converted to a value of type 'std::nullptr_t'}}
68