Clang Project

clang_source_code/test/SemaCXX/constexpr-default-arg.cpp
1// RUN: %clang_cc1 -std=c++1y -S -o - -emit-llvm -verify %s
2
3namespace default_arg_temporary {
4
5constexpr bool equals(const float& arg = 1.0f) {
6  return arg == 1.0f;
7}
8
9constexpr const int &x(const int &p = 0) {
10  return p;
11}
12
13struct S {
14  constexpr S(const int &a = 0) {}
15};
16
17void test_default_arg2() {
18  // This piece of code used to cause an assertion failure in
19  // CallStackFrame::createTemporary because the same MTE is used to initilize
20  // both elements of the array (see PR33140).
21  constexpr S s[2] = {};
22
23  // This piece of code used to cause an assertion failure in
24  // CallStackFrame::createTemporary because multiple CXXDefaultArgExpr share
25  // the same MTE (see PR33140).
26  static_assert(equals() && equals(), "");
27
28  // Test that constant expression evaluation produces distinct lvalues for
29  // each call.
30  static_assert(&x() != &x(), "");
31}
32
33// Check that multiple CXXDefaultInitExprs don't cause an assertion failure.
34struct A { int &&r = 0; }; // expected-note 2{{default member initializer}}
35struct B { A x, y; };
36B b = {}; // expected-warning 2{{not supported}}
37
38}
39