52 lines · cpp
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 CHECK2// RUN: %clang_cc1 -std=c++11 %s -triple x86_64-linux-gnu -emit-llvm -o - -fexceptions -fcxx-exceptions -pedantic-errors | FileCheck %s --check-prefixes CHECK3// RUN: %clang_cc1 -std=c++14 %s -triple x86_64-linux-gnu -emit-llvm -o - -fexceptions -fcxx-exceptions -pedantic-errors | FileCheck %s --check-prefixes CHECK4// RUN: %clang_cc1 -std=c++17 %s -triple x86_64-linux-gnu -emit-llvm -o - -fexceptions -fcxx-exceptions -pedantic-errors | FileCheck %s --check-prefixes CHECK5// RUN: %clang_cc1 -std=c++20 %s -triple x86_64-linux-gnu -emit-llvm -o - -fexceptions -fcxx-exceptions -pedantic-errors | FileCheck %s --check-prefixes CHECK6// RUN: %clang_cc1 -std=c++23 %s -triple x86_64-linux-gnu -emit-llvm -o - -fexceptions -fcxx-exceptions -pedantic-errors | FileCheck %s --check-prefixes CHECK7// RUN: %clang_cc1 -std=c++2c %s -triple x86_64-linux-gnu -emit-llvm -o - -fexceptions -fcxx-exceptions -pedantic-errors | FileCheck %s --check-prefixes CHECK8 9#if __cplusplus == 199711L10#define static_assert(expr) __extension__ _Static_assert(expr)11#define noexcept throw()12#endif13 14namespace cwg6 { // cwg6: 2.715#if __cplusplus >= 201103L16struct 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.23constexpr int PassByValue(Counter c) { return c.copies; }24constexpr int PassByValue2(Counter c) { return PassByValue(c); }25constexpr int PassByValue3(Counter c) { return PassByValue2(c); }26static_assert(PassByValue(Counter(0)) == 0, "expect no copies");27static_assert(PassByValue2(Counter(0)) == 1, "expect 1 copy");28static_assert(PassByValue3(Counter(0)) == 2, "expect 2 copies");29#endif30 31struct A {32 A() noexcept;33 A(const A&) noexcept;34 ~A() noexcept;35};36 37inline void f(A a) noexcept {}38 39// CHECK-LABEL: define {{.*}} @_ZN4cwg64callEv40void call() {41 A a;42 // We copy the parameter here, even though object is not mutated by f and43 // 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 cwg652