|
6 | 6 | // RUN: %clang_cc1 -std=c++23 %s -triple x86_64-linux-gnu -emit-llvm -o - -fexceptions -fcxx-exceptions -pedantic-errors | FileCheck %s --check-prefixes CHECK |
7 | 7 | // RUN: %clang_cc1 -std=c++2c %s -triple x86_64-linux-gnu -emit-llvm -o - -fexceptions -fcxx-exceptions -pedantic-errors | FileCheck %s --check-prefixes CHECK |
8 | 8 |
|
| 9 | +#if __cplusplus == 199711L |
| 10 | +#define static_assert(expr) __extension__ _Static_assert(expr) |
| 11 | +#define noexcept throw() |
| 12 | +#endif |
| 13 | + |
9 | 14 | namespace cwg6 { // cwg6: yes |
| 15 | +#if __cplusplus >= 201103L |
| 16 | +struct Counter { |
| 17 | + int copies; |
| 18 | + constexpr Counter(int copies) : copies(copies) {} |
| 19 | + constexpr Counter(const Counter& other) : copies(other.copies + 1) {} |
| 20 | +}; |
| 21 | + |
| 22 | +// Passing an lvalue by value makes a non-elidable copy. |
| 23 | +constexpr int PassByValue(Counter c) { return c.copies; } |
| 24 | +constexpr int PassByValue2(Counter c) { return PassByValue(c); } |
| 25 | +constexpr int PassByValue3(Counter c) { return PassByValue2(c); } |
| 26 | +static_assert(PassByValue(Counter(0)) == 0, "expect no copies"); |
| 27 | +static_assert(PassByValue2(Counter(0)) == 1, "expect 1 copy"); |
| 28 | +static_assert(PassByValue3(Counter(0)) == 2, "expect 2 copies"); |
| 29 | +#endif |
10 | 30 |
|
11 | 31 | struct A { |
12 | | - A(); |
13 | | - A(const A&); |
14 | | - ~A(); |
| 32 | + A() noexcept; |
| 33 | + A(const A&) noexcept; |
| 34 | + ~A() noexcept; |
15 | 35 | }; |
16 | 36 |
|
17 | | -inline void f(A a) {} |
| 37 | +inline void f(A a) noexcept {} |
18 | 38 |
|
19 | 39 | // CHECK-LABEL: define {{.*}} @_ZN4cwg64callEv |
20 | 40 | void call() { |
21 | 41 | A a; |
22 | 42 | // We copy the parameter here, even though object is not mutated by f and |
23 | 43 | // otherwise satisfies the criteria for the proposed CWG6 optimization. |
24 | | - // CHECK: {{call|invoke}} {{.*}} @_ZN4cwg61AC1ERKS0_ |
25 | | - // CHECK: {{call|invoke}} {{.*}} @_ZN4cwg61fE |
| 44 | + // CHECK: call {{.*}} @_ZN4cwg61AC1ERKS0_( |
| 45 | + // CHECK: call {{.*}} @_ZN4cwg61fENS_1AE( |
26 | 46 | f(a); |
27 | | - // CHECK: {{call|invoke}} {{.*}} @_ZN4cwg61AD1Ev |
28 | | - // CHECK: {{call|invoke}} {{.*}} @_ZN4cwg61AD1Ev |
| 47 | + // CHECK: call {{.*}} @_ZN4cwg61AD1Ev( |
| 48 | + // CHECK: call {{.*}} @_ZN4cwg61AD1Ev( |
29 | 49 | } |
30 | 50 |
|
31 | 51 | } // namespace cwg6 |
0 commit comments