typedef __SIZE_TYPE__ size_t;
namespace basic_sema {
consteval int f1(int i) {
return i;
}
consteval constexpr int f2(int i) {
return i;
}
constexpr auto l_eval = [](int i) consteval {
return i;
};
constexpr consteval int f3(int i) {
return i;
}
struct A {
consteval int f1(int i) const {
return i;
}
consteval A(int i);
consteval A() = default;
consteval ~A() = default; };
consteval struct B {};
consteval typedef B b;
consteval int redecl() {return 0;} constexpr int redecl() {return 0;}
consteval int i = 0;
consteval int;
consteval int f1() {}
struct C {
C() {}
~C() {}
};
struct D {
C c;
consteval D() = default; consteval ~D() = default; };
struct E : C {
consteval ~E() {} };
}
consteval int main() { return 0;
}
consteval int f_eval(int i) {
return i;
}
namespace taking_address {
using func_type = int(int);
func_type* p1 = (&f_eval);
func_type* p7 = __builtin_addressof(f_eval);
auto p = f_eval;
auto m1 = &basic_sema::A::f1;
auto l1 = &decltype(basic_sema::l_eval)::operator();
consteval int f(int i) {
return i;
}
auto ptr = &f;
auto f1() {
return &f;
}
}
namespace invalid_function {
struct A {
consteval void *operator new(size_t count);
consteval void *operator new[](size_t count);
consteval void operator delete(void* ptr);
consteval void operator delete[](void* ptr);
consteval ~A() {}
};
}
namespace nested {
consteval int f() {
return 0;
}
consteval int f1(...) {
return 1;
}
enum E {};
using T = int(&)();
consteval auto operator+ (E, int(*a)()) {
return 0;
}
void d() {
auto i = f1(E() + &f);
}
auto l0 = [](auto) consteval {
return 0;
};
int i0 = l0(&f1);
int i1 = f1(l0(4));
int i2 = f1(&f1, &f1, &f1, &f1, &f1, &f1, &f1);
int i3 = f1(f1(f1(&f1, &f1), f1(&f1, &f1), f1(f1(&f1, &f1), &f1)));
}
namespace user_defined_literal {
consteval int operator"" _test(unsigned long long i) {
return 0;
}
int i = 0_test;
auto ptr = &operator"" _test;
consteval auto operator"" _test1(unsigned long long i) {
return &f_eval;
}
auto i1 = 0_test1;
}
namespace return_address {
consteval int f() {
return 0;
}
consteval int(*ret1(int i))() {
return &f;
}
auto ptr = ret1(0);
struct A {
consteval int f(int) {
return 0;
}
};
using mem_ptr_type = int (A::*)(int);
template<mem_ptr_type ptr>
struct C {};
C<&A::f> c;
consteval mem_ptr_type ret2() {
return &A::f;
}
C<ret2()> c1;
}
namespace context {
int g_i;
consteval int f(int) {
return 0;
}
constexpr int c_i = 0;
int t1 = f(g_i);
int t3 = f(c_i);
constexpr int f_c(int i) {
int t = f(i);
return f(0);
}
consteval int f_eval(int i) {
return f(i);
}
auto l0 = [](int i) consteval {
return f(i);
};
auto l1 = [](int i) constexpr {
int t = f(i);
return f(0);
};
}
namespace std {
template <typename T> struct remove_reference { using type = T; };
template <typename T> struct remove_reference<T &> { using type = T; };
template <typename T> struct remove_reference<T &&> { using type = T; };
template <typename T>
constexpr typename std::remove_reference<T>::type&& move(T &&t) noexcept {
return static_cast<typename std::remove_reference<T>::type &&>(t);
}
}
namespace temporaries {
struct A {
consteval int ret_i() const { return 0; }
consteval A ret_a() const { return A{}; }
constexpr ~A() { }
};
consteval int by_value_a(A a) { return a.ret_i(); }
consteval int const_a_ref(const A &a) {
return a.ret_i();
}
consteval int rvalue_ref(const A &&a) {
return a.ret_i();
}
consteval const A &to_lvalue_ref(const A &&a) {
return a;
}
void test() {
constexpr A a {};
{ int k = A().ret_i(); }
{ A k = A().ret_a(); }
{ A k = to_lvalue_ref(A()); } { A k = to_lvalue_ref(A().ret_a()); } { int k = A().ret_a().ret_i(); }
{ int k = by_value_a(A()); }
{ int k = const_a_ref(A()); }
{ int k = const_a_ref(a); }
{ int k = rvalue_ref(A()); }
{ int k = rvalue_ref(std::move(a)); }
{ int k = const_a_ref(A().ret_a()); }
{ int k = const_a_ref(to_lvalue_ref(A().ret_a())); }
{ int k = const_a_ref(to_lvalue_ref(std::move(a))); }
{ int k = by_value_a(A().ret_a()); }
{ int k = by_value_a(to_lvalue_ref(std::move(a))); }
{ int k = (A().ret_a(), A().ret_i()); }
{ int k = (const_a_ref(A().ret_a()), A().ret_i()); }}
}
namespace alloc {
consteval int f() {
int *A = new int(0);
return *A;
}
int i1 = f();
struct A {
int* p = new int(42);
consteval int ret_i() const { return p ? *p : 0; }
consteval A ret_a() const { return A{}; }
constexpr ~A() { delete p; }
};
consteval int by_value_a(A a) { return a.ret_i(); }
consteval int const_a_ref(const A &a) {
return a.ret_i();
}
consteval int rvalue_ref(const A &&a) {
return a.ret_i();
}
consteval const A &to_lvalue_ref(const A &&a) {
return a;
}
void test() {
constexpr A a{ nullptr };
{ int k = A().ret_i(); }
{ A k = A().ret_a(); } { A k = to_lvalue_ref(A()); } { A k = to_lvalue_ref(A().ret_a()); }
{ int k = A().ret_a().ret_i(); }
{ int k = by_value_a(A()); }
{ int k = const_a_ref(A()); }
{ int k = const_a_ref(a); }
{ int k = rvalue_ref(A()); }
{ int k = rvalue_ref(std::move(a)); }
{ int k = const_a_ref(A().ret_a()); }
{ int k = const_a_ref(to_lvalue_ref(A().ret_a())); }
{ int k = const_a_ref(to_lvalue_ref(std::move(a))); }
{ int k = by_value_a(A().ret_a()); }
{ int k = by_value_a(to_lvalue_ref(static_cast<const A&&>(a))); }
{ int k = (A().ret_a(), A().ret_i()); } { int k = (const_a_ref(A().ret_a()), A().ret_i()); }
}
}
namespace self_referencing {
struct S {
S* ptr = nullptr;
constexpr S(int i) : ptr(this) {
if (this == ptr && i)
ptr = nullptr;
}
constexpr ~S() {}
};
consteval S f(int i) {
return S(i);
}
void test() {
S s(1);
s = f(1);
s = f(0); }
struct S1 {
S1* ptr = nullptr;
consteval S1(int i) : ptr(this) {
if (this == ptr && i)
ptr = nullptr;
}
constexpr ~S1() {}
};
void test1() {
S1 s(1);
s = S1(1);
s = S1(0); }
}
namespace ctor {
consteval int f_eval() { return 0;
}
namespace std {
struct strong_ordering {
int n;
static const strong_ordering less, equal, greater;
};
constexpr strong_ordering strong_ordering::less = {-1};
constexpr strong_ordering strong_ordering::equal = {0};
constexpr strong_ordering strong_ordering::greater = {1};
constexpr bool operator!=(strong_ordering, int);
}
namespace override {
struct A {
virtual consteval void f(); virtual void g(); };
struct B : A {
consteval void f();
void g();
};
struct C : A {
void f(); consteval void g(); };
namespace implicit_equals_1 {
struct Y;
struct X {
std::strong_ordering operator<=>(const X&) const;
constexpr bool operator==(const X&) const;
virtual consteval bool operator==(const Y&) const; };
struct Y : X {
std::strong_ordering operator<=>(const Y&) const = default;
};
}
namespace implicit_equals_2 {
struct Y;
struct X {
constexpr std::strong_ordering operator<=>(const X&) const;
constexpr bool operator==(const X&) const;
virtual bool operator==(const Y&) const; };
struct Y : X {
consteval std::strong_ordering operator<=>(const Y&) const = default;
};
}
}
namespace operator_rewrite {
struct A {
friend consteval int operator<=>(const A&, const A&) { return 0; }
};
const bool k = A() < A();
static_assert(!k);
A a;
bool k2 = A() < a;
struct B {
friend consteval int operator<=>(const B &l, const B &r) { return r.n - l.n; } int n;
};
static_assert(B() >= B());
B b; bool k3 = B() < b; }
struct A {
int(*ptr)();
consteval A(int(*p)() = nullptr) : ptr(p) {}
};
struct B {
int(*ptr)();
B() : ptr(nullptr) {}
consteval B(int(*p)(), int) : ptr(p) {}
};
void test() {
{ A a; }
{ A a(&f_eval); } { B b(nullptr, 0); }
{ B b(&f_eval, 0); } { A a{}; }
{ A a{&f_eval}; } { B b{nullptr, 0}; }
{ B b{&f_eval, 0}; } { A a = A(); }
{ A a = A(&f_eval); } { B b = B(nullptr, 0); }
{ B b = B(&f_eval, 0); } { A a = A{}; }
{ A a = A{&f_eval}; } { B b = B{nullptr, 0}; }
{ B b = B{&f_eval, 0}; } { A a; a = A(); }
{ A a; a = A(&f_eval); } { B b; b = B(nullptr, 0); }
{ B b; b = B(&f_eval, 0); } { A a; a = A{}; }
{ A a; a = A{&f_eval}; } { B b; b = B{nullptr, 0}; }
{ B b; b = B{&f_eval, 0}; } { A* a; a = new A(); }
{ A* a; a = new A(&f_eval); } { B* b; b = new B(nullptr, 0); }
{ B* b; b = new B(&f_eval, 0); } { A* a; a = new A{}; }
{ A* a; a = new A{&f_eval}; } { B* b; b = new B{nullptr, 0}; }
{ B* b; b = new B{&f_eval, 0}; } }
}
namespace copy_ctor {
consteval int f_eval() { return 0;
}
struct Copy {
int(*ptr)();
constexpr Copy(int(*p)() = nullptr) : ptr(p) {}
consteval Copy(const Copy&) = default;
};
constexpr const Copy &to_lvalue_ref(const Copy &&a) {
return a;
}
void test() {
constexpr const Copy C;
{ Copy c(C); }
{ Copy c((Copy(&f_eval))); } { Copy c(std::move(C)); }
{ Copy c(std::move(Copy(&f_eval))); } { Copy c(to_lvalue_ref((Copy(&f_eval)))); } { Copy c(to_lvalue_ref(std::move(C))); }
{ Copy c(to_lvalue_ref(std::move(Copy(&f_eval)))); } { Copy c = Copy(C); }
{ Copy c = Copy(Copy(&f_eval)); } { Copy c = Copy(std::move(C)); }
{ Copy c = Copy(std::move(Copy(&f_eval))); } { Copy c = Copy(to_lvalue_ref(Copy(&f_eval))); } { Copy c = Copy(to_lvalue_ref(std::move(C))); }
{ Copy c = Copy(to_lvalue_ref(std::move(Copy(&f_eval)))); } { Copy c; c = Copy(C); }
{ Copy c; c = Copy(Copy(&f_eval)); } { Copy c; c = Copy(std::move(C)); }
{ Copy c; c = Copy(std::move(Copy(&f_eval))); } { Copy c; c = Copy(to_lvalue_ref(Copy(&f_eval))); } { Copy c; c = Copy(to_lvalue_ref(std::move(C))); }
{ Copy c; c = Copy(to_lvalue_ref(std::move(Copy(&f_eval)))); } { Copy* c; c = new Copy(C); }
{ Copy* c; c = new Copy(Copy(&f_eval)); } { Copy* c; c = new Copy(std::move(C)); }
{ Copy* c; c = new Copy(std::move(Copy(&f_eval))); } { Copy* c; c = new Copy(to_lvalue_ref(Copy(&f_eval))); } { Copy* c; c = new Copy(to_lvalue_ref(std::move(C))); }
{ Copy* c; c = new Copy(to_lvalue_ref(std::move(Copy(&f_eval)))); }}
}
namespace unevaluated {
template <typename T, typename U> struct is_same { static const bool value = false; };
template <typename T> struct is_same<T, T> { static const bool value = true; };
long f(); auto consteval g(auto a) {
return a;
}
auto e = g(f());
using T = decltype(g(f()));
static_assert(is_same<long, T>::value);
}
namespace value_dependent {
consteval int foo(int x) {
return x;
}
template <int X> constexpr int bar() {
return foo(X);
}
template <typename T> constexpr int baz() {
constexpr int t = sizeof(T);
return foo(t);
}
static_assert(bar<15>() == 15);
static_assert(baz<int>() == sizeof(int));
}
namespace default_argument {
consteval int foo() { return 1; }
consteval int bar(int i = foo()) { return i * i; }
struct Test1 {
Test1(int i = bar(13)) {}
void v(int i = bar(13) * 2 + bar(15)) {}
};
Test1 t1;
struct Test2 {
constexpr Test2(int i = bar()) {}
constexpr void v(int i = bar(bar(bar(foo())))) {}
};
Test2 t2;
}
namespace PR50779 {
struct derp {
int b = 0;
};
constexpr derp d;
struct test {
consteval int operator[](int i) const { return {}; }
consteval const derp * operator->() const { return &d; }
consteval int f() const { return 12; } };
constexpr test a;
constexpr int s = a.operator[](1);
constexpr int t = a[1];
constexpr int u = a.operator->()->b;
constexpr int v = a->b;
constexpr int w = (a.*&test::f)(); constexpr int x = a.f();
int w2 = (a.*&test::f)(); }
namespace PR48235 {
consteval int d() {
return 1;
}
struct A {
consteval int a() const { return 1; }
void b() {
this->a() + d(); }
void c() {
a() + d(); }
};
}
namespace NamespaceScopeConsteval {
struct S {
int Val; consteval S() {}
};
S s1;
template <typename Ty>
struct T {
Ty Val; consteval T() {}
};
T<int> t;
}
namespace Issue54578 {
inline consteval unsigned char operator""_UC(const unsigned long long n) {
return static_cast<unsigned char>(n);
}
inline constexpr char f1(const auto octet) {
return 4_UC;
}
template <typename Ty>
inline constexpr char f2(const Ty octet) {
return 4_UC;
}
void test() {
static_assert(f1('a') == 4);
static_assert(f2('a') == 4);
constexpr int c = f1('a') + f2('a');
static_assert(c == 8);
}
}
namespace GH51695 {
template <typename T>
struct type_t {};
template <typename...>
struct list_t {};
template <typename T, typename... Ts>
consteval auto pop_front(list_t<T, Ts...>) -> auto {
return list_t<Ts...>{};
}
template <typename... Ts, typename F>
consteval auto apply(list_t<Ts...>, F fn) -> auto {
return fn(type_t<Ts>{}...);
}
void test1() {
constexpr auto x = apply(pop_front(list_t<char, char>{}),
[]<typename... Us>(type_t<Us>...) { return 42; });
static_assert(x == 42);
}
consteval bool zero() { return false; }
template <typename F>
consteval bool foo(bool, F f) {
return f();
}
void test2() {
constexpr auto x = foo(zero(), []() { return true; });
static_assert(x);
}
template <typename F>
consteval auto bar(F f) { return f;}
void test3() {
constexpr auto t1 = bar(bar(bar(bar([]() { return true; }))))();
static_assert(t1);
int a = 1; auto t2 = bar(bar(bar(bar([=]() { return a; }))))();
constexpr auto t3 = bar(bar([x=bar(42)]() { return x; }))();
static_assert(t3==42);
constexpr auto t4 = bar(bar([x=bar(42)]() consteval { return x; }))();
static_assert(t4==42);
}
}
namespace GH50455 {
void f() {
[]() consteval { int i{}; }();
[]() consteval { int i{}; ++i; }();
}
void g() {
(void)[](int i) consteval { return i; }(0);
(void)[](int i) consteval { return i; }(0);
}
}