diff options
Diffstat (limited to 'clang/test')
-rw-r--r-- | clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p3.cpp | 5 | ||||
-rw-r--r-- | clang/test/SemaCXX/cxx1z-constexpr-lambdas.cpp | 29 |
2 files changed, 30 insertions, 4 deletions
diff --git a/clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p3.cpp b/clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p3.cpp index cc3917093ec..dd26f691569 100644 --- a/clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p3.cpp +++ b/clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p3.cpp @@ -157,11 +157,8 @@ constexpr int DisallowedStmtsCXX1Y_2_1() { constexpr int DisallowedStmtsCXX1Y_3() { // - a try-block, try {} catch (...) {} -#ifndef CXX2A +#if !defined(CXX2A) // expected-error@-2 {{use of this statement in a constexpr function is a C++2a extension}} -#ifndef CXX1Y - // expected-error@-4 {{use of this statement in a constexpr function is a C++14 extension}} -#endif #endif return 0; } diff --git a/clang/test/SemaCXX/cxx1z-constexpr-lambdas.cpp b/clang/test/SemaCXX/cxx1z-constexpr-lambdas.cpp index bdf6847ec3d..12fbcfcf44a 100644 --- a/clang/test/SemaCXX/cxx1z-constexpr-lambdas.cpp +++ b/clang/test/SemaCXX/cxx1z-constexpr-lambdas.cpp @@ -1,4 +1,5 @@ // RUN: %clang_cc1 -std=c++1z -verify -fsyntax-only -fblocks %s -fcxx-exceptions +// RUN: %clang_cc1 -std=c++2a -verify -fsyntax-only -fblocks %s -fcxx-exceptions // RUN: %clang_cc1 -std=c++1z -verify -fsyntax-only -fblocks -fdelayed-template-parsing %s -fcxx-exceptions // RUN: %clang_cc1 -std=c++14 -verify -fsyntax-only -fblocks %s -DCPP14_AND_EARLIER -fcxx-exceptions @@ -25,6 +26,34 @@ namespace ns2 { auto L = [](int I) constexpr { asm("non-constexpr"); }; //expected-error{{not allowed in constexpr function}} } // end ns1 +// This is not constexpr until C++20, as the requirements on constexpr +// functions don't permit try-catch blocks. +#if __cplusplus <= 201703L +// expected-error@#try-catch {{constant expression}} +// expected-note@#try-catch {{non-constexpr function 'operator()'}} +// expected-note@#try-catch {{declared here}} +#endif +constexpr int try_catch = [] { // #try-catch + try { return 0; } catch (...) { return 1; } +}(); + +// These lambdas have constexpr operator() even though they can never produce a +// constant expression. +auto never_constant_1 = [] { // expected-note {{here}} + volatile int n = 0; + return n; +}; +auto never_constant_2 = [] () -> int { // expected-note {{here}} +}; +struct test_never_constant { + #if __cplusplus >= 201703L + // expected-error@+3 {{non-constexpr declaration of 'operator()' follows constexpr declaration}} + // expected-error@+3 {{non-constexpr declaration of 'operator()' follows constexpr declaration}} + #endif + friend auto decltype(never_constant_1)::operator()() const; + friend int decltype(never_constant_2)::operator()() const; +}; + } // end ns test_constexpr_checking namespace test_constexpr_call { |