xref: /aosp_15_r20/external/clang/test/SemaCXX/cxx1z-constexpr-lambdas.cpp (revision 67e74705e28f6214e480b399dd47ea732279e315)
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
3 // RUN: %clang_cc1 -std=c++1z -verify -fsyntax-only -fblocks -fms-extensions %s
4 // RUN: %clang_cc1 -std=c++1z -verify -fsyntax-only -fblocks -fdelayed-template-parsing -fms-extensions %s
5 
6 namespace test_constexpr_checking {
7 
8 namespace ns1 {
9   struct NonLit { ~NonLit(); };  //expected-note{{not literal}}
__anon2d3cfe550102(NonLit NL) 10   auto L = [](NonLit NL) constexpr { }; //expected-error{{not a literal type}}
11 } // end ns1
12 
13 namespace ns2 {
__anon2d3cfe550202(int I) 14   auto L = [](int I) constexpr { asm("non-constexpr");  }; //expected-error{{not allowed in constexpr function}}
15 } // end ns1
16 
17 } // end ns test_constexpr_checking
18 
19 namespace test_constexpr_call {
20 
21 namespace ns1 {
__anon2d3cfe550302(int I) 22   auto L = [](int I) { return I; };
23   static_assert(L(3) == 3);
24 } // end ns1
25 namespace ns2 {
__anon2d3cfe550402(auto a) 26   auto L = [](auto a) { return a; };
27   static_assert(L(3) == 3);
28   static_assert(L(3.14) == 3.14);
29 }
30 namespace ns3 {
__anon2d3cfe550502(auto a) 31   auto L = [](auto a) { asm("non-constexpr"); return a; }; //expected-note{{declared here}}
32   constexpr int I =  //expected-error{{must be initialized by a constant expression}}
33       L(3); //expected-note{{non-constexpr function}}
34 }
35 
36 } // end ns test_constexpr_call