-
Notifications
You must be signed in to change notification settings - Fork 15.1k
Open
Labels
clang:frontendLanguage frontend issues, e.g. anything involving "Sema"Language frontend issues, e.g. anything involving "Sema"needs-reductionLarge reproducer that should be reduced into a simpler formLarge reproducer that should be reduced into a simpler form
Description
Here's a case where CTAD for template aliases feature isn't working. Minimal code is copied below, but here also are godbolt links:
- https://godbolt.org/z/6jdo4qGG9 clang-trunk doesn't work
- https://godbolt.org/z/3KoG4PfWT GCC supports this, as far back as 12.1
#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
Labels
clang:frontendLanguage frontend issues, e.g. anything involving "Sema"Language frontend issues, e.g. anything involving "Sema"needs-reductionLarge reproducer that should be reduced into a simpler formLarge reproducer that should be reduced into a simpler form