https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106085

            Bug ID: 106085
           Summary: It's unclear what the __has_trivial* builtins do after
                    P0848 (Conditionally Trivial Special Member Functions)
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: roi.jacobson1 at gmail dot com
  Target Milestone: ---

I'm currently in the process of implementing P0848 for Clang, and I'm wondering
what to do about the __has_trivial_* builtins, especially since they consider
deleted functions as trivial, which goes against the spirit of 'deleted
functions are ineligible and should not affect the type traits'.

I tried to play with it a bit in GCC and the builtin seems pretty inconsistent:

#include <concepts>

template<class T>
struct A {
    A() = delete;
    A() requires std::same_as<T, int> = delete;
};

template<class T>
struct B {
    B();
    B() requires std::same_as<T, int> = delete;
};

template<class T>
struct C {
    C();
    C() requires std::same_as<T, int> = default;
};

static_assert(__has_trivial_constructor(A<int>));
static_assert(!__is_trivially_constructible(A<int>));

static_assert(!__has_trivial_constructor(B<int>));
static_assert(!__is_trivially_constructible(B<int>));

static_assert(__has_trivial_constructor(C<int>));
static_assert(__is_trivially_constructible(C<int>));


Is there logic behind this? Those builtins are technically deprecated in Clang
but I would like to support GCC compatibility if possible.

If not, it might be a good idea to add a warning about using those builtins or
potentially start to deprecate them in GCC as well.

Reply via email to