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