Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions clang/test/CXX/drs/cwg0xx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,24 @@ namespace cwg5 { // cwg5: 3.1
const C c = e;
} // namespace cwg5

namespace cwg6 { // cwg6 codegen is tested in cwg6.cpp
#if __cplusplus >= 201103L
struct Counter {
int copies;
constexpr Counter(int copies) : copies(copies) {}
constexpr Counter(const Counter& other) : copies(other.copies + 1) {}
};

// Passing an lvalue by value makes a non-elidable copy.
constexpr int PassByValue(Counter c) { return c.copies; }
constexpr int PassByValue2(Counter c) { return PassByValue(c); }
constexpr int PassByValue3(Counter c) { return PassByValue2(c); }
static_assert(PassByValue(Counter(0)) == 0, "expect no copies");
static_assert(PassByValue2(Counter(0)) == 1, "expect 1 copy");
static_assert(PassByValue3(Counter(0)) == 2, "expect 2 copies");
#endif
} // namespace cwg6

namespace cwg7 { // cwg7: 3.4
class A { public: ~A(); };
class B : virtual private A {}; // #cwg7-B
Expand Down
16 changes: 16 additions & 0 deletions clang/test/CXX/drs/cwg28xx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,22 @@ namespace cwg2819 { // cwg2819: 19 c++26
#endif
} // namespace cwg2819

namespace cwg2823 { // cwg2823: no
#if __cplusplus >= 201103L
constexpr int *p = 0;
constexpr int *q1 = &*p; // expected-error {{constant expression}} expected-note {{dereferencing a null pointer}}
// FIXME: invalid: dereferencing a null pointer.
constexpr int *q2 = &p[0];

int arr[32];
constexpr int *r = arr;
// FIXME: invalid: dereferencing a past-the-end pointer.
constexpr int *s1 = &*(r + 32);
// FIXME: invalid: dereferencing a past-the-end pointer.
constexpr int *s2 = &r[32];
#endif
}

namespace cwg2847 { // cwg2847: 19 review 2024-03-01

#if __cplusplus >= 202002L
Expand Down
34 changes: 34 additions & 0 deletions clang/test/CXX/drs/cwg2xx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,37 @@ namespace cwg211 { // cwg211: 2.7
};
} // namespace cwg211

namespace cwg212 { // cwg212: yes
template<typename T> struct Base;
template<typename T> struct Derived;

int *overload(void*);
float *overload(Base<int>*);
double *overload(Base<long>*);

void f(Derived<int> *p) {
// OK, calls void* overload.
int *a = overload(p);

Base<int> *q = p; // expected-error {{cannot initialize}}
}

template<typename T> struct Base {};
template<typename T> struct Derived : Base<T> {};

void g(Derived<long> *p) {
// OK, instantiates and calls Base<long>* overlod.
double *b = overload(p);
(void)b;
}

void h(Derived<float> *p) {
// OK, instantiates and converts.
Base<float> *q = p;
(void)q;
}
}

namespace cwg213 { // cwg213: 2.7
template <class T> struct A : T {
void h(T t) {
Expand Down Expand Up @@ -593,6 +624,9 @@ namespace cwg231 { // cwg231: 2.7
}
} // namespace cwg231

// 232 is NAD; the desired behavior is described in 2823.
// cwg232: dup 2823

// cwg234: na
// cwg235: na

Expand Down
31 changes: 31 additions & 0 deletions clang/test/CXX/drs/cwg6.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// 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
// 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
// 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
// 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
// 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
// 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
// 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

namespace cwg6 { // cwg6: yes

struct A {
A();
A(const A&);
~A();
};

inline void f(A a) {}

// CHECK-LABEL: define {{.*}} @_ZN4cwg64callEv
void call() {
A a;
// We copy the parameter here, even though object is not mutated by f and
// otherwise satisfies the criteria for the proposed CWG6 optimization.
// CHECK: {{call|invoke}} {{.*}} @_ZN4cwg61AC1ERKS0_
// CHECK: {{call|invoke}} {{.*}} @_ZN4cwg61fE
f(a);
// CHECK: {{call|invoke}} {{.*}} @_ZN4cwg61AD1Ev
// CHECK: {{call|invoke}} {{.*}} @_ZN4cwg61AD1Ev
}

} // namespace cwg6
Loading