Skip to content

Class with constructor template requiring copyable argument is not copyable by itself #53454

Closed
@Fedr

Description

@Fedr

In the following program struct A has a constructor template A(T) requiring that the type T be copy-constructible. At the same time A itself must have implicitly defined copy-constructor:

#include <type_traits>

struct A {
    template <class T>
    A(T) requires(std::is_copy_constructible_v<T>) {}
};
static_assert(std::is_copy_constructible_v<A>);

and the last static_assert(std::is_copy_constructible_v) passes in GCC and MSVC, but Clang rejects it, complaining:

error: substitution into constraint expression resulted in a non-constant expression
    A(T) requires(std::is_copy_constructible_v<T>) {}
                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/12.0.1/../../../../include/c++/12.0.1/type_traits:971:30: note: while checking constraint satisfaction for template 'A<A>' required here
    : public __bool_constant<__is_constructible(_Tp, _Args...)>
                             ^~~~~~~~~~~~~~~~~~
...

Demo: https://gcc.godbolt.org/z/shKe7W1jr

Related discussion: https://stackoverflow.com/q/70874679/7325599

Metadata

Metadata

Assignees

No one assigned

    Labels

    c++20clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerconfirmedVerified by a second party

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions