blob: 90a07665cbf7115302c1261e3aa2fe48ff9821d3 [file] [log] [blame]
Faisal Valia734ab92016-03-26 16:11:37 +00001// RUN: %clang_cc1 -std=c++1z -verify -fsyntax-only -fblocks %s
2// RUN: %clang_cc1 -std=c++1z -verify -fsyntax-only -fblocks -fdelayed-template-parsing %s
Faisal Valic6b9be22016-07-23 04:05:19 +00003// RUN: %clang_cc1 -std=c++14 -verify -fsyntax-only -fblocks %s -DCPP14_AND_EARLIER
Faisal Valia734ab92016-03-26 16:11:37 +00004
Faisal Vali5e550182016-07-31 01:19:17 +00005
6namespace test_lambda_is_literal {
7#ifdef CPP14_AND_EARLIER
8//expected-error@+4{{not a literal type}}
9//expected-note@+2{{not an aggregate and has no constexpr constructors}}
10#endif
11auto L = [] { };
12constexpr int foo(decltype(L) l) { return 0; }
13
14}
15
Faisal Valic6b9be22016-07-23 04:05:19 +000016#ifndef CPP14_AND_EARLIER
Faisal Valia734ab92016-03-26 16:11:37 +000017namespace test_constexpr_checking {
18
19namespace ns1 {
20 struct NonLit { ~NonLit(); }; //expected-note{{not literal}}
21 auto L = [](NonLit NL) constexpr { }; //expected-error{{not a literal type}}
22} // end ns1
23
24namespace ns2 {
25 auto L = [](int I) constexpr { asm("non-constexpr"); }; //expected-error{{not allowed in constexpr function}}
26} // end ns1
27
28} // end ns test_constexpr_checking
29
30namespace test_constexpr_call {
31
32namespace ns1 {
33 auto L = [](int I) { return I; };
34 static_assert(L(3) == 3);
35} // end ns1
36namespace ns2 {
37 auto L = [](auto a) { return a; };
38 static_assert(L(3) == 3);
39 static_assert(L(3.14) == 3.14);
40}
41namespace ns3 {
42 auto L = [](auto a) { asm("non-constexpr"); return a; }; //expected-note{{declared here}}
43 constexpr int I = //expected-error{{must be initialized by a constant expression}}
44 L(3); //expected-note{{non-constexpr function}}
45}
46
Faisal Valic6b9be22016-07-23 04:05:19 +000047} // end ns test_constexpr_call
48
Faisal Vali0528a312016-11-13 06:09:16 +000049namespace test_captureless_lambda {
50void f() {
51 const char c = 'c';
52 auto L = [] { return c; };
53 constexpr char C = L();
54}
55
56void f(char c) { //expected-note{{declared here}}
57 auto L = [] { return c; }; //expected-error{{cannot be implicitly captured}} expected-note{{lambda expression begins here}}
58 int I = L();
59}
Faisal Valic6b9be22016-07-23 04:05:19 +000060
Faisal Vali0528a312016-11-13 06:09:16 +000061}
62#endif // ndef CPP14_AND_EARLIER