brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.2 KiB · 5b06c7d Raw
105 lines · cpp
1// RUN: %clang_cc1 -fsyntax-only -std=c++2b %s -verify2// RUN: %clang_cc1 -fsyntax-only -std=c++2b %s -verify -fexperimental-new-constant-interpreter3// expected-no-diagnostics4 5template <typename Base>6struct Wrap : Base {7 8};9 10struct S {11    constexpr int f(this const S&) {12        return 42;13    }14    constexpr int f(this const S&, auto&&... args) {15        return (args + ... + 0);16    }17    constexpr int operator[](this const S&) {18        return 42;19    }20    constexpr int operator[](this const S& self, int i) {21        return i + self.base;22    }23    constexpr int operator()(this const S&) {24        return 42;25    }26    constexpr int operator()(this const S& self, int i) {27        return self.base + i;28    }29    constexpr bool operator==(this const S& self, auto && test) {30        return self.base == test;31    };32    constexpr int operator*(this const S& self) {33        return self.base + 22;34    };35    constexpr operator Wrap<S> (this const S& self) {36        return Wrap<S>{self};37    };38    constexpr int operator <<(this Wrap<S> self, int i) {39        return self.base+i;40    }41 42    int base = 20;43};44 45consteval void test() {46    constexpr S s;47    static_assert(s.f() == 42);48    static_assert(s[] == 42);49    static_assert(s[22] == 42);50    static_assert(s.f() == 42);51    static_assert(s() == 42);52    static_assert(s(22) == 42);53    static_assert(s == 20);54    static_assert(s != 0);55    static_assert(*s == 42);56    static_assert((s << 11) == 31);57}58 59namespace GH68070 {60 61constexpr auto f = [x = 3]<typename Self>(this Self&& self) {62    return x;63};64 65auto g = [x = 3]<typename Self>(this Self&& self) {66    return x;67};68 69int test() {70  constexpr int a = f();71  static_assert(a == 3);72  return f() + g();73}74 75}76 77namespace GH142835 {78struct MoveMe {79  MoveMe& operator=(this MoveMe&, const MoveMe&) = default;80  constexpr MoveMe& operator=(this MoveMe& self, MoveMe&& other) {81    self.value = other.value;82    other.value = 0;83    return self;84  }85  int value = 4242;86};87 88struct S {89  constexpr S& operator=(this S&, const S&) = default;90  S& operator=(this S&, S&&) = default;91 92  MoveMe move_me;93};94 95constexpr bool f() {96  S s1{};97  S s2{};98  s2 = s1;99  return true;100}101 102static_assert(f());103 104}105