Skip to content

[Clang][concepts] Conditional explicit specifier is checked too early in constrained constructor #59827

Closed
@JMazurkiewicz

Description

@JMazurkiewicz

Repro (3rd version, 2nd version reproduced other possible bug; see edit history):

template<class X>
constexpr X failure() {
    return nullptr;
}

struct T {
    template<class X>
        requires false
    constexpr explicit(failure<X>()) T(X) { }

    T(int) { }
};

static T t(5);

Expected: correct compilation

Got:

<source>:3:12: error: cannot initialize return object of type 'int' with an rvalue of type 'std::nullptr_t'
    return nullptr;
           ^~~~~~~
<source>:9:24: note: in instantiation of function template specialization 'failure<int>' requested here
    constexpr explicit(failure<X>()) T(X) { }
                       ^
<source>:14:10: note: while substituting deduced template arguments into function template 'T' [with X = int]
static T t(5);
         ^

Compiler explorer: https://godbolt.org/z/sPsGh46Gs
Discovered in: microsoft/STL#3323

Metadata

Metadata

Assignees

No one assigned

    Labels

    c++20clang:frontendLanguage frontend issues, e.g. anything involving "Sema"conceptsC++20 concepts

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions