| 
 | 1 | +// RUN: %clang_cc1 -std=c++98 %s -triple x86_64-linux-gnu -emit-llvm -o - -fexceptions -fcxx-exceptions -pedantic-errors | FileCheck %s --check-prefixes CHECK  | 
 | 2 | +// RUN: %clang_cc1 -std=c++11 %s -triple x86_64-linux-gnu -emit-llvm -o - -fexceptions -fcxx-exceptions -pedantic-errors | FileCheck %s --check-prefixes CHECK  | 
 | 3 | +// RUN: %clang_cc1 -std=c++14 %s -triple x86_64-linux-gnu -emit-llvm -o - -fexceptions -fcxx-exceptions -pedantic-errors | FileCheck %s --check-prefixes CHECK  | 
 | 4 | +// RUN: %clang_cc1 -std=c++17 %s -triple x86_64-linux-gnu -emit-llvm -o - -fexceptions -fcxx-exceptions -pedantic-errors | FileCheck %s --check-prefixes CHECK  | 
 | 5 | +// RUN: %clang_cc1 -std=c++20 %s -triple x86_64-linux-gnu -emit-llvm -o - -fexceptions -fcxx-exceptions -pedantic-errors | FileCheck %s --check-prefixes CHECK  | 
 | 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 | +// 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 | + | 
 | 9 | +#if __cplusplus == 199711L  | 
 | 10 | +#define static_assert(expr) __extension__ _Static_assert(expr)  | 
 | 11 | +#define noexcept throw()  | 
 | 12 | +#endif  | 
 | 13 | + | 
 | 14 | +namespace cwg6 { // cwg6: 2.7  | 
 | 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  | 
 | 30 | + | 
 | 31 | +struct A {  | 
 | 32 | +  A() noexcept;  | 
 | 33 | +  A(const A&) noexcept;  | 
 | 34 | +  ~A() noexcept;  | 
 | 35 | +};  | 
 | 36 | + | 
 | 37 | +inline void f(A a) noexcept {}  | 
 | 38 | + | 
 | 39 | +// CHECK-LABEL: define {{.*}} @_ZN4cwg64callEv  | 
 | 40 | +void call() {  | 
 | 41 | +  A a;  | 
 | 42 | +  // We copy the parameter here, even though object is not mutated by f and  | 
 | 43 | +  // otherwise satisfies the criteria for the proposed CWG6 optimization.  | 
 | 44 | +  // CHECK: call {{.*}} @_ZN4cwg61AC1ERKS0_(  | 
 | 45 | +  // CHECK: call {{.*}} @_ZN4cwg61fENS_1AE(  | 
 | 46 | +  f(a);  | 
 | 47 | +  // CHECK: call {{.*}} @_ZN4cwg61AD1Ev(  | 
 | 48 | +  // CHECK: call {{.*}} @_ZN4cwg61AD1Ev(  | 
 | 49 | +}  | 
 | 50 | + | 
 | 51 | +} // namespace cwg6  | 
0 commit comments