[Issue 23924] New: Template function overload fails with enum and typesafe variadic template parameters
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu May 18 14:31:19 UTC 2023
https://issues.dlang.org/show_bug.cgi?id=23924
Issue ID: 23924
Summary: Template function overload fails with enum and
typesafe variadic template parameters
Product: D
Version: D2
Hardware: x86
OS: Windows
Status: NEW
Severity: normal
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: john.michael.hall at gmail.com
In the code below, there is a struct that has enum and variadic template
parameters. There are two functions, one that is basically taking any of the
structs without variadic parameters and the other takes anything else. The
compiler isn't able to match an object with enum and variadic parameters to a
function.
The problem seems associated with the enum and how it interacts with variadic
template parameters. As I show below, you would get the errors you expect when
it doesn't take an enum template parameter.
```d
enum Bar {A, B}
struct Foo(Bar bar, U...) {}
void foo(Bar bar)(Foo!(bar) x) {}
void foo(T)(T x) {}
void main()
{
Foo!(Bar.A) x;
Foo!(Bar.A, int) y;
foo(x);
foo(y);
}
```
produces the output (with the latest DMD on run.dlang.org, I believe 2.103 or
so)
```
onlineapp.d(14,8): Error: none of the overloads of template `onlineapp.foo` are
callable using argument types `!()(Foo!(Bar.A, int))`
onlineapp.d(6,6): Candidates are: `foo(Bar bar)(Foo!bar x)`
onlineapp.d(7,6): `foo(T)(T x)`
Error dmd failed with exit code 1.
```
which is strange since the second foo function should be able to take anything.
If you replace the enum with some kind of concrete type
```
struct Foo(T, U...) {}
void foo(T)(Foo!T x) {}
void foo(T)(T x) {}
void main()
{
Foo!(double) x;
Foo!(double, int) y;
foo(x);
foo(y);
}
```
then you get an error about foo(x) matching both, which is what I would expect.
If you comment that out, then foo(y) compiles, which is what I would expect.
--
More information about the Digitalmars-d-bugs
mailing list