| 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 |
| 3 |
|
| 4 |
namespace default_arg_temporary { |
| 5 |
|
| 6 |
constexpr bool equals(const float& arg = 1.0f) { |
| 7 |
return arg == 1.0f; |
| 8 |
} |
| 9 |
|
| 10 |
constexpr const int &x(const int &p = 0) { |
| 11 |
return p; |
| 12 |
} |
| 13 |
|
| 14 |
struct S { |
| 15 |
constexpr S(const int &a = 0) {} |
| 16 |
}; |
| 17 |
|
| 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] = {}; |
| 23 |
|
| 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(), ""); |
| 28 |
|
| 29 |
// Test that constant expression evaluation produces distinct lvalues for |
| 30 |
// each call. |
| 31 |
static_assert(&x() != &x(), ""); |
| 32 |
} |
| 33 |
|
| 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 |
| 38 |
|
| 39 |
} |