brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.0 KiB · cd786b1 Raw
39 lines · cpp
1// RUN: %clang_cc1 -std=c++26 -fsyntax-only -fcxx-exceptions -verify=ref,both %s2// RUN: %clang_cc1 -std=c++26 -fsyntax-only -fcxx-exceptions -verify=expected,both %s -fexperimental-new-constant-interpreter3 4namespace std {5  using size_t = decltype(sizeof(0));6}7 8namespace VoidCast {9  constexpr void* p = nullptr;10  constexpr int* q = static_cast<int*>(p);11  static_assert(q == nullptr);12}13 14namespace ReplaceableAlloc {15  struct F {16    static void* operator new(std::size_t n) {17      return nullptr; // both-warning {{should not return a null pointer}}18    }19  };20 21  constexpr F *createF() {22    return new F(); // both-note {{call to class-specific 'operator new'}}23  }24 25  constexpr bool foo() {26    F *f = createF(); // both-note {{in call to}}27 28    delete f;29    return true;30  }31  static_assert(foo()); // both-error {{not an integral constant expression}} \32                        // both-note {{in call to}}33}34 35constexpr int a = 12;36constexpr const int *b = &a;37constexpr int *f = (int*)(void*)b;38static_assert(*f == 12);39