brintos

brintos / llvm-project-archived public Read only

0
0
Text · 5.4 KiB · 4098beb Raw
128 lines · cpp
1// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++26 -Wno-ext-cxx-type-aware-allocators -fexceptions    -fsized-deallocation    -faligned-allocation2// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++26 -Wno-ext-cxx-type-aware-allocators -fexceptions -fno-sized-deallocation    -faligned-allocation3// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++26 -Wno-ext-cxx-type-aware-allocators -fexceptions    -fsized-deallocation -fno-aligned-allocation4// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++26 -Wno-ext-cxx-type-aware-allocators -fexceptions -fno-sized-deallocation -fno-aligned-allocation5// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++26 -Wno-ext-cxx-type-aware-allocators -fexceptions    -fsized-deallocation    -faligned-allocation -fexperimental-new-constant-interpreter6// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++26 -Wno-ext-cxx-type-aware-allocators -fexceptions -fno-sized-deallocation    -faligned-allocation -fexperimental-new-constant-interpreter7// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++26 -Wno-ext-cxx-type-aware-allocators -fexceptions    -fsized-deallocation -fno-aligned-allocation -fexperimental-new-constant-interpreter8// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++26 -Wno-ext-cxx-type-aware-allocators -fexceptions -fno-sized-deallocation -fno-aligned-allocation -fexperimental-new-constant-interpreter9 10 11namespace std {12  template <class T> struct type_identity {};13  enum class align_val_t : __SIZE_TYPE__ {};14  struct destroying_delete_t { explicit destroying_delete_t() = default; };15}16 17using size_t = __SIZE_TYPE__;18 19struct S1 {20  constexpr explicit S1() : i(5) {  }21  const int i;22};23 24void *operator new(std::type_identity<S1>, size_t sz, std::align_val_t); // #125void operator delete(std::type_identity<S1>, void* ptr, size_t sz, std::align_val_t); // #226 27constexpr int ensure_consteval_skips_typed_allocators() {28  // Verify we dont resolve typed allocators in const contexts29  auto * s = new S1();30  auto result = s->i;31  delete s;32  return result;33};34 35struct S2 {36  constexpr explicit S2() : i(5) {  }37  const int i;38};39 40void *operator new(std::type_identity<S2>, size_t sz, std::align_val_t) = delete; // #341void operator delete(std::type_identity<S2>, void* ptr, size_t sz, std::align_val_t) = delete; // #442 43constexpr int ensure_constexpr_retains_types_at_runtime() {44  // Verify we dont resolve typed allocators in const contexts45  S2 *s = new S2();46  // expected-error@-1 {{call to deleted function 'operator new'}}47  // expected-note@#1 {{candidate function not viable: no known conversion from 'type_identity<S2>' to 'type_identity<S1>' for 1st argument}}48  // expected-note@#3 {{candidate function has been explicitly deleted}}49  auto result = s->i;50  delete s;51  // expected-error@-1 {{attempt to use a deleted function}}52  // expected-note@#4 {{'operator delete' has been explicitly marked deleted here}}53  return result;54};55 56 57struct S3 {58  constexpr explicit S3() : i(5) {  }59  const int i;60  template <typename T> void* operator new(std::type_identity<T>, size_t sz, std::align_val_t) = delete; // #561  template <typename T> void operator delete(std::type_identity<T>, void *, size_t sz, std::align_val_t) = delete; // #662};63 64template <typename T> void* operator new(std::type_identity<T>, size_t sz, std::align_val_t) = delete; // #765template <typename T> void operator delete(std::type_identity<T>, void *, size_t sz, std::align_val_t) = delete; // #866 67constexpr int constexpr_vs_inclass_operators() {68  S3 *s;69  if consteval {70    s = ::new S3();71    // expected-error@-1 {{call to deleted function 'operator new'}}72    // expected-note@#1 {{candidate function not viable: no known conversion from 'type_identity<S3>' to 'type_identity<S1>' for 1st argument}}73    // expected-note@#3 {{candidate function not viable: no known conversion from 'type_identity<S3>' to 'type_identity<S2>' for 1st argument}}74    // expected-note@#7 {{candidate function [with T = S3] has been explicitly deleted}}75  } else {76    s = new S3();77    // expected-error@-1 {{call to deleted function 'operator new'}}78    // expected-note@#5 {{candidate function [with T = S3] has been explicitly deleted}}79  }80  auto result = s->i;81  if consteval {82    ::delete s;83    // expected-error@-1 {{attempt to use a deleted function}}84    // expected-note@#8 {{'operator delete<S3>' has been explicitly marked deleted here}}85  } else {86    delete s;87    // expected-error@-1 {{attempt to use a deleted function}}88    // expected-note@#6 {{'operator delete<S3>' has been explicitly marked deleted here}}89  }90  return result;91};92 93// Test a variety of valid constant evaluation paths94struct S4 {95  int i = 1;96  constexpr S4() __attribute__((noinline)) {}97};98 99void* operator new(std::type_identity<S4>, size_t sz, std::align_val_t);100void operator delete(std::type_identity<S4>, void *, size_t sz, std::align_val_t);101 102constexpr int do_dynamic_alloc(int n) {103  S4* s = new S4;104  int result = n * s->i;105  delete s;106  return result;107}108 109template <int N> struct Tag {110};111 112static constexpr int force_do_dynamic_alloc = do_dynamic_alloc(5);113 114constexpr int test_consteval_calling_constexpr(int i) {115  if consteval {116    return do_dynamic_alloc(2 * i);117  }118  return do_dynamic_alloc(3 * i);119}120 121int test_consteval(int n, Tag<test_consteval_calling_constexpr(2)>, Tag<do_dynamic_alloc(3)>) {122  static const int t1 = test_consteval_calling_constexpr(4);123  static const int t2 = do_dynamic_alloc(5);124  int t3 = test_consteval_calling_constexpr(6);125  int t4 = do_dynamic_alloc(7);126  return t1 * t2 * t3 * t4;127}128