1 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
2
3 namespace PR15360 {
4 template<typename R, typename U, R F>
f()5 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 *'}}
test()6 void test() {
7 f<int(int), int(*)(int), nullptr>(); // expected-note{{in instantiation of}}
8 f<int[3], int*, nullptr>(); // expected-note{{in instantiation of}}
9 }
10 }
11
12 namespace CanonicalNullptr {
13 template<typename T> struct get { typedef T type; };
14 struct X {};
15 template<typename T, typename get<T *>::type P = nullptr> struct A {};
16 template<typename T, typename get<decltype((T(), nullptr))>::type P = nullptr> struct B {};
17 template<typename T, typename get<T X::*>::type P = nullptr> struct C {};
18
19 template<typename T> A<T> MakeA();
20 template<typename T> B<T> MakeB();
21 template<typename T> C<T> MakeC();
22 A<int> a = MakeA<int>();
23 B<int> b = MakeB<int>();
24 C<int> c = MakeC<int>();
25 }
26
27 namespace Auto {
28 template<auto> struct A { }; // expected-error {{until C++17}}
29 }
30
31 namespace check_conversion_early {
32 struct X {};
33 template<int> struct A {};
34 template<X &x> struct A<x> {}; // expected-error {{not implicitly convertible}}
35
operator intcheck_conversion_early::Y36 struct Y { constexpr operator int() const { return 0; } };
37 template<Y &y> struct A<y> {}; // expected-error {{cannot be deduced}} expected-note {{'y'}}
38 }
39
40 namespace ReportCorrectParam {
41 template <int a, unsigned b, int c>
TempFunc()42 void TempFunc() {}
43
Useage()44 void Useage() {
45 //expected-error@+2 {{no matching function}}
46 //expected-note@-4 {{candidate template ignored: invalid explicitly-specified argument for template parameter 'b'}}
47 TempFunc<1, -1, 1>();
48 }
49 }
50
51 namespace PR42513 {
52 template<typename X, int Ret = WidgetCtor((X*)nullptr)> void f();
53 constexpr int WidgetCtor(struct X1*);
54
55 struct X1 {
56 friend constexpr int WidgetCtor(X1*);
57 };
58 template<typename X1>
59 struct StandardWidget {
WidgetCtor(X1 *)60 friend constexpr int WidgetCtor(X1*) {
61 return 0;
62 }
63 };
64 template struct StandardWidget<X1>;
65
use()66 void use() { f<X1>(); }
67 }
68
69 namespace ReferenceToConstexpr {
70 struct A { const char *str = "hello"; };
71 constexpr A a;
72 template<const A &r, typename T> struct B {
73 static_assert(__builtin_strcmp(r.str, "hello") == 0, "");
74 };
75 template<const A &r> struct C {
fReferenceToConstexpr::C76 template<typename T> void f(B<r, T>, T) {}
77 };
f(C<a> ca)78 void f(C<a> ca) { ca.f({}, 0); }
79 }
80
81 using FourChars = const char[4];
82 constexpr FourChars kEta = "Eta";
83 constexpr const char kDes[4] = "Des";
84 constexpr const char *kNull = "Phi";
85 constexpr const char **kZero[] = {};
86
87 template <const char *, typename T> class Column {};
88 template <const char[], typename T> class Dolumn {};
89 template <const char (*)[4], typename T> class Folumn {};
90 template <FourChars *, typename T> class Golumn {};
91 template <const char *const *, typename T> class Holumn {};
92 template <const char *const *const *, typename T> class Jolumn {};
93 template <const char **const (*)[0], typename T> class Iolumn {};
94
95 class container {
96 public:
97 int a;
98 };
99 template <int container::*> class Kolumn {};
100
lookup()101 void lookup() {
102 Column<kEta, double>().ls(); // expected-error {{<kEta,}}
103 Column<kDes, double>().ls(); // expected-error {{<kDes,}}
104 Column<nullptr, double>().ls(); // expected-error {{<nullptr,}}
105 Dolumn<kEta, double>().ls(); // expected-error {{<kEta,}}
106 Dolumn<kDes, double>().ls(); // expected-error {{<kDes,}}
107 Folumn<&kEta, double>().ls(); // expected-error {{<&kEta,}}
108 Folumn<&kDes, double>().ls(); // expected-error {{<&kDes,}}
109 Golumn<&kEta, double>().ls(); // expected-error {{<&kEta,}}
110 Golumn<&kDes, double>().ls(); // expected-error {{<&kDes,}}
111 Holumn<&kNull, double>().ls(); // expected-error {{<&kNull,}}
112 Jolumn<kZero, double>().ls(); // expected-error {{<kZero,}}
113 Iolumn<&kZero, double>().ls(); // expected-error {{<&kZero,}}
114 Kolumn<&container::a>().ls(); // expected-error {{<&container::a}}
115 Kolumn<nullptr>().ls(); // expected-error {{<nullptr}}
116 }
117