LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 50740 - __is_trivial doesn't work in the presence of special member functions with trailing requires clauses
Summary: __is_trivial doesn't work in the presence of special member functions with tr...
Status: RESOLVED INVALID
Alias: None
Product: clang
Classification: Unclassified
Component: C++2a (show other bugs)
Version: trunk
Hardware: PC All
: P enhancement
Assignee: Unassigned Clang Bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-06-16 08:44 PDT by Louis Dionne
Modified: 2021-06-16 12:09 PDT (History)
4 users (show)

See Also:
Fixed By Commit(s):


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Louis Dionne 2021-06-16 08:44:02 PDT
When compiled with Clang ToT, the following code incorrectly believes that allocator<void> is non-trivial, when it should be trivial:

cat <<EOF | clang++ -xc++ - -std=c++2a -fsyntax-only
#include <type_traits>

template <class T>
struct allocator {
    allocator() = default;
    allocator() requires(!std::is_void_v<T>) { }
};

static_assert(__is_trivial(allocator<void>));

int main() { }
EOF

This works on GCC. Godbolt link: https://godbolt.org/z/4osMGWTne.

I tracked the issue down a bit, and  I think the issue is that when QualType::isTrivialType() queries whether the class declaration has a non-trivial default constructor (via CXXRecordDecl::hasNonTrivialDefaultConstructor()), it incorrectly believes that it's the case.
Comment 1 Louis Dionne 2021-06-16 09:18:15 PDT
I'm not a Clang expert, but I think CXXRecordDecl::addedMember() is incorrectly setting up this declaration:

    allocator() requires(!std::is_void_v<T>) { } // where T = void

as a special member function that is non-trivial and user-provided, even though should (?) not be considered because of the trailing requires clause.
Comment 2 Richard Smith 2021-06-16 12:05:18 PDT
This is part of P0848R3, which we don't yet implement.
Comment 3 Louis Dionne 2021-06-16 12:09:29 PDT
Oh, thanks, I thought http://wg21.link/P0848 was just adding the trailing requires clauses to constructors with that use case in mind, but I had it wrong. So this is simply not implemented.

I guess we can close as INVALID, since this is not a bug, merely a missing feature.