1 // RUN: %clang_cc1 -verify -std=c++11 %s
2 // RUN: %clang_cc1 -verify -std=c++11 -fdelayed-template-parsing %s
8 T (X::* f1())(int) { return 0; }
14 template void f0
<int>();
23 Y() { V
= ValueType(); }
37 // Instantiation of local classes with virtual functions.
38 namespace local_class_with_virtual_functions
{
39 template <typename T
> struct X
{ };
40 template <typename T
> struct Y
{ };
44 struct Z
: public X
<Y
<T
>*> {
45 virtual void g(Y
<T
>* y
) { }
46 void g2(int x
) {(void)x
;}
53 void test() { f
<S
>(); }
60 typedef int (X::*pmf_type
)();
61 class X
: public T
{ };
63 pmf_type pmf
= &T::foo
;
66 struct Y
{ int foo(); };
68 template void foo
<Y
>();
71 namespace TemplatePacksAndLambdas
{
72 template <typename
...T
> int g(T
...);
74 template <typename
...T
> static void f(int f
= g([]{ static T t
; return ++t
; }()...)) {}
76 void h() { S::f
<int, int, int>(); }
80 template <class Thing
> void forEach(Thing t
) { t
.func(); }
82 template <typename T
> void doIt() {
84 void func() { (void)i
; }
98 template <typename F
> bool apply(F f
) { return f(); }
101 template <typename
> struct T
{
106 bool operator()() { return x
== 0; }
113 void call() { T
<int>().foo(); }
117 template <class T
> void foo(const T
&t
) { t
.foo(); }
119 template <class F
> void bar(F
*f
) {
122 void foo() const { fn(); }
129 void test() { bar(go
); }
135 template <typename T
> static void foo(T function
);
136 template <typename T
> static void bar(T function
);
137 template <typename T
> static void func(T function
);
140 template <typename T
> void C::foo(T function
) { function(); }
142 template <typename T
> void C::bar(T function
) {
143 foo([&function
]() { function(); });
146 template <typename T
> void C::func(T function
) {
150 Struct(T function
) : mFunction(function
) {};
157 bar(Struct(function
));
167 template <typename _Functor
> function(_Functor __f
) { __f(); }
169 template <typename Func
> function
exec_func(Func f
) {
171 functor(Func f
) : func(f
) {}
172 void operator()() const { func(); }
178 void operator()() const {}
188 class C
: public C
<int> {}; // expected-error{{within its own definition}}
190 template <typename X
>
196 void f() { F
<int>(); }
202 int operator()() const { return 0; }
207 template <bool = true> int make_seed_pair() noexcept
{
215 return make_seed_pair();
220 // Forward declarations
222 template<typename T
> void f1() {
226 template void f1
<int>();
228 template<typename T
> void f1a() {
232 template void f1a
<int>();
234 template<typename T
> void f2() {
235 void g2(enum x2
); // expected-error{{ISO C++ forbids forward references to 'enum' types}}
238 template void f2
<int>();
240 template<typename T
> void f3() {
243 enum class x3
{ nothing
};
245 template void f3
<int>();
248 template<typename T
> void f4() {
249 void g4(struct x4
{} x
); // expected-error{{'x4' cannot be defined in a parameter type}}
251 template void f4
<int>();
253 template<typename T
> void f4a() {
254 void g4(union x4
{} x
); // expected-error{{'x4' cannot be defined in a parameter type}}
256 template void f4a
<int>();
259 template <class T
> void f();
260 template <class T
> struct S1
{
266 template struct S1
<int>;
268 template <class T
> struct S2
{
270 f
<enum new_enum
>(); // expected-error{{ISO C++ forbids forward references to 'enum' types}}
273 template struct S2
<int>;
275 template <class T
> struct S3
{
281 template struct S3
<int>;
283 template <class T
> struct S4
{
289 template struct S4
<int>;
291 template <class T
> struct S4a
{
297 template struct S4a
<int>;
299 template <class T
> struct S5
{
300 enum local
{ nothing
};
305 template struct S5
<int>;
307 template <class T
> struct S7
{
308 enum class local
{ nothing
};
313 template struct S7
<int>;
316 template <class T
> void fff(T
*x
);
317 template <class T
> struct S01
{
324 template struct S01
<int>;
326 template <class T
> struct S01a
{
333 template struct S01a
<int>;
335 template <class T
> struct S02
{
336 enum local
{ nothing
};
342 template struct S02
<int>;
344 template <class T
> struct S03
{
345 enum class local
{ nothing
};
351 template struct S03
<int>;
354 template <class T
> struct S04
{
360 template struct S04
<int>;
362 template <class T
> struct S04a
{
368 template struct S04a
<int>;
370 template <class T
> struct S05
{
376 template struct S05
<int>;
378 template <class T
> struct S06
{
380 class { virtual void mmm() {} } x
;
384 template struct S06
<int>;
388 template <typename T
>
391 static constexpr int get() { return 42; }
393 constexpr int n
= N::get();
394 static_assert(n
== 42, "n == 42");
397 void g() { f
<void>(); }
402 template<typename T
> void f1() {
403 struct S
{ // expected-note{{in instantiation of member class 'S' requested here}}
404 void g1(int n
= T::error
); // expected-error{{type 'int' cannot be used prior to '::' because it has no members}} \
405 // expected-note {{in instantiation of default function argument expression for 'g1<int>' required here}}
408 template void f1
<int>(); // expected-note{{in instantiation of function template specialization 'PR21332::f1<int>' requested here}}
410 template<typename T
> void f2() {
411 struct S
{ // expected-note{{in instantiation of member class 'S' requested here}}
412 void g2() noexcept(T::error
); // expected-error{{type 'int' cannot be used prior to '::' because it has no members}}
415 template void f2
<int>(); // expected-note{{in instantiation of function template specialization 'PR21332::f2<int>' requested here}}
417 template<typename T
> void f3() {
419 val
= T::error
; // expected-error{{expected '}' or ','}} expected-error{{type 'int' cannot be used prior to '::' because it has no members}}
422 template void f3
<int>(); //expected-note{{in instantiation of function template specialization 'PR21332::f3<int>' requested here}}
424 template<typename T
> void f4() {
426 val
= T::error
; // expected-error{{expected '}' or ','}} expected-error{{type 'int' cannot be used prior to '::' because it has no members}}
429 template void f4
<int>(); // expected-note{{in instantiation of function template specialization 'PR21332::f4<int>' requested here}}
431 template<typename T
> void f5() {
432 class S
{ // expected-note {{in instantiation of default member initializer 'PR21332::f5()::S::val' requested here}}
433 int val
= T::error
; // expected-error {{type 'int' cannot be used prior to '::' because it has no members}}
436 template void f5
<int>(); // expected-note {{in instantiation of function template specialization 'PR21332::f5<int>' requested here}}
438 template<typename T
> void f6() {
439 class S
{ // expected-note {{in instantiation of member function 'PR21332::f6()::S::get' requested here}}
441 class S2
{ // expected-note {{in instantiation of member class 'S2' requested here}}
442 void g1(int n
= T::error
); // expected-error {{type 'int' cannot be used prior to '::' because it has no members}} \
443 // expected-note {{in instantiation of default function argument expression for 'g1<int>' required here}}
448 template void f6
<int>(); // expected-note{{in instantiation of function template specialization 'PR21332::f6<int>' requested here}}
450 template<typename T
> void f7() {
451 struct S
{ void g() noexcept(undefined_val
); }; // expected-error{{use of undeclared identifier 'undefined_val'}}
453 template void f7
<int>();
456 // Ensure that we correctly perform implicit conversions when instantiating the
457 // default arguments of local functions.
458 namespace rdar23721638
{
460 A(const char *) = delete; // expected-note 2 {{explicitly marked deleted here}}
463 template <typename T
> void foo() {
464 struct Inner
{ // expected-note {{in instantiation}}
465 void operator()(T a
= "") {} // expected-error {{conversion function from 'const char[1]' to 'rdar23721638::A' invokes a deleted function}} \
466 // expected-note {{in instantiation of default function argument expression for 'operator()<rdar23721638::A>' required here}} \
467 // expected-note {{passing argument to parameter 'a' here}}
471 template void foo
<A
>(); // expected-note {{in instantiation}}
473 template <typename T
> void bar() {
474 auto lambda
= [](T a
= "") {}; // expected-error {{conversion function from 'const char[1]' to 'rdar23721638::A' invokes a deleted function}} \
475 // expected-note {{in instantiation of default function argument expression for 'operator()<rdar23721638::A>' required here}} \
476 // expected-note {{passing argument to parameter 'a' here}} \
477 // expected-note {{while substituting into a lambda}}
480 template void bar
<A
>(); // expected-note {{in instantiation}}
483 namespace anon_union_default_member_init
{
484 template<typename T
> void f() {
491 void g() { f
<int>(); }
495 template <typename T
>
496 void f(int x
= [](T x
= nullptr) -> int { return x
; }());
497 // expected-error@-1 {{cannot initialize a parameter of type 'int' with an rvalue of type 'std::nullptr_t'}}
498 // expected-note@-2 {{in instantiation of default function argument expression for 'operator()<int>' required here}}
499 // expected-note@-3 {{passing argument to parameter 'x' here}}
500 // expected-note@-4 {{while substituting into a lambda}}
502 void g() { f
<int>(); }
503 // expected-note@-1 {{in instantiation of default function argument expression for 'f<int>' required here}}
506 namespace LambdaInDefaultMemberInitializer
{
507 template<typename T
> void f() {
509 void *p
= [this] { return &p
; }();
512 template void f
<int>();