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