[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / SemaCXX / constexpr-default-arg.cpp
blob901123bfb359ff17bba26b8d4eb7fffe384ed333
1 // RUN: %clang_cc1 -std=c++1y -o - -emit-llvm -verify %s
2 // RUN: %clang_cc1 -std=c++1y -fexperimental-new-constant-interpreter -o - -emit-llvm -verify %s
4 namespace default_arg_temporary {
6 constexpr bool equals(const float& arg = 1.0f) {
7 return arg == 1.0f;
10 constexpr const int &x(const int &p = 0) {
11 return p;
14 struct S {
15 constexpr S(const int &a = 0) {}
18 void test_default_arg2() {
19 // This piece of code used to cause an assertion failure in
20 // CallStackFrame::createTemporary because the same MTE is used to initilize
21 // both elements of the array (see PR33140).
22 constexpr S s[2] = {};
24 // This piece of code used to cause an assertion failure in
25 // CallStackFrame::createTemporary because multiple CXXDefaultArgExpr share
26 // the same MTE (see PR33140).
27 static_assert(equals() && equals(), "");
29 // Test that constant expression evaluation produces distinct lvalues for
30 // each call.
31 static_assert(&x() != &x(), "");
34 // Check that multiple CXXDefaultInitExprs don't cause an assertion failure.
35 struct A { int &&r = 0; };
36 struct B { A x, y; };
37 B b = {}; // expected-no-diagnostics