Faisal Vali | a734ab9 | 2016-03-26 16:11:37 +0000 | [diff] [blame] | 1 | // 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 Vali | c6b9be2 | 2016-07-23 04:05:19 +0000 | [diff] [blame] | 3 | // RUN: %clang_cc1 -std=c++14 -verify -fsyntax-only -fblocks %s -DCPP14_AND_EARLIER |
Faisal Vali | a734ab9 | 2016-03-26 16:11:37 +0000 | [diff] [blame] | 4 | |
Faisal Vali | 5e55018 | 2016-07-31 01:19:17 +0000 | [diff] [blame] | 5 | |
| 6 | namespace 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 |
| 11 | auto L = [] { }; |
| 12 | constexpr int foo(decltype(L) l) { return 0; } |
| 13 | |
| 14 | } |
| 15 | |
Faisal Vali | c6b9be2 | 2016-07-23 04:05:19 +0000 | [diff] [blame] | 16 | #ifndef CPP14_AND_EARLIER |
Faisal Vali | a734ab9 | 2016-03-26 16:11:37 +0000 | [diff] [blame] | 17 | namespace test_constexpr_checking { |
| 18 | |
| 19 | namespace 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 | |
| 24 | namespace 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 | |
| 30 | namespace test_constexpr_call { |
| 31 | |
| 32 | namespace ns1 { |
| 33 | auto L = [](int I) { return I; }; |
| 34 | static_assert(L(3) == 3); |
| 35 | } // end ns1 |
| 36 | namespace ns2 { |
| 37 | auto L = [](auto a) { return a; }; |
| 38 | static_assert(L(3) == 3); |
| 39 | static_assert(L(3.14) == 3.14); |
| 40 | } |
| 41 | namespace 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 Vali | c6b9be2 | 2016-07-23 04:05:19 +0000 | [diff] [blame] | 47 | } // end ns test_constexpr_call |
| 48 | |
Faisal Vali | 0528a31 | 2016-11-13 06:09:16 +0000 | [diff] [blame] | 49 | namespace test_captureless_lambda { |
| 50 | void f() { |
| 51 | const char c = 'c'; |
| 52 | auto L = [] { return c; }; |
| 53 | constexpr char C = L(); |
| 54 | } |
| 55 | |
| 56 | void 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 Vali | c6b9be2 | 2016-07-23 04:05:19 +0000 | [diff] [blame] | 60 | |
Faisal Vali | 0528a31 | 2016-11-13 06:09:16 +0000 | [diff] [blame] | 61 | } |
| 62 | #endif // ndef CPP14_AND_EARLIER |