Skip to content

C++20: Deduction guides ignored for class type placeholder template argument #73666

Closed
@devreal

Description

@devreal

I experimented with placeholders for deduced class types in templates using std::array (passing it as a template argument without explicitly specifying std::array during instantiation, instead relying on deduction guides). I found that GCC uses deduction guides to deduce the argument type while Clang seems to ignore them.

Here is the smallest example I could come up with based on std::array:

// trimmed-down std::array
template<class T, int I>
struct A {
    T x[I];
};

// deduction guide (like std::array)
template< class T, class... U >
A( T, U... ) -> A<T, 1 + sizeof...(U)>;

template<A a> void foo() { }

void bar() {
    foo<{1}>(); // works with GCC, fails with Clang
}

See also: https://godbolt.org/z/7vWa3zKoj

Apologies if this was reported before, I tried to search the open issues but couldn't find anything related to this. Also, I am not sure whether this is legal in C++20, I was just surprised to see it work in GCC but not in Clang. Please feel free to close this issue if this is not legal.

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions