Skip to content

Deduction guide fails for CTAD for template aliases #111216

@agraham-roku

Description

@agraham-roku

Here's a case where CTAD for template aliases feature isn't working. Minimal code is copied below, but here also are godbolt links:

#include <chrono>

template <typename Rep, typename Period>
struct duration {
    constexpr duration(Rep r) : v{r} {}

    template <typename R2, typename P2>
    constexpr duration(duration<R2, P2> const& d)
            : v{std::chrono::duration_cast<decltype(v)>(d.v)} {}

    std::chrono::duration<Rep, Period> v;
};

template <typename Rep, typename Period = std::ratio<1>>
using seconds = duration<Rep, Period>;

template <typename Rep> using milliseconds =
        seconds<Rep, std::chrono::milliseconds::period>;

template <typename Rep, typename Period, typename Period2>
duration(duration<Rep, Period>) -> duration<Rep, Period2>;

constexpr auto d1 = seconds{1};
constexpr auto d2 = milliseconds{d1};
static_assert(d2.v.count() == 1000);

int main() {}

The clang error is:

<source>:21:1: error: deduction guide template contains a template parameter that cannot be deduced
   21 | duration(duration<Rep, Period>) -> duration<Rep, Period2>;
      | ^
<source>:20:51: note: non-deducible template parameter 'Period2'
   20 | template <typename Rep, typename Period, typename Period2>
      |                                                   ^
1 error generated.
Compiler returned: 1

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:frontendLanguage frontend issues, e.g. anything involving "Sema"needs-reductionLarge reproducer that should be reduced into a simpler form

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions