Bug 13283 – dmd fails to generate ambiguous overload error
Status
RESOLVED
Resolution
MOVED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2014-08-11T11:35:47Z
Last change time
2022-08-25T14:39:37Z
Assigned to
No Owner
Creator
Vlad Levenfeld
Comments
Comment #0 by vlevenfeld — 2014-08-11T11:35:47Z
I have a generic Vector struct that is constructed by helper
functions that deduce the length and element type and forward the
arguments to the appropriate constructor. Almost all of them had
a constraint on them that required the length of the vector the
be at least 2, but the Vector struct itself had no such
constraint, and one of the helper functions was missing it as
well.
When I added the constraint to either the Vector struct or the
helper function (I've since added them to both) then everything
links fine. It looks like what was happening was that a "fill
constructor helper function" (intended use: vector!4 (x) =>
vector (x, x, x, x)) was routing to a "variadic constructor
helper function" (vector (args) => vector!(args.length)(args))
that attempted to generate a 1-element vector and somewhere along
the way - linker error.
There are the mangled names that the linker could not resolve
references to:
`_D3evx7vectors16__T6VectorVm1TdZ6Vector6__initZ`
`_D3evx7vectors16__T6VectorVm1TdZ6Vector6__ctorMFNaNbNcNfdZS3evx7vectors16__T6VectorVm1TdZ6Vector`
the second of which demangles to this:
pure nothrow ref @safe evx.vectors.Vector!(1uL, double).Vector
evx.vectors.Vector!(1uL, double).Vector.__ctor(double)
So, there's my one-element vector constructor, which is likely
having a hard time with the following overloads:
this (Elements...)(Elements elements)
if (Elements.length == length)
{
foreach (i, element; elements)
components[i] = element;
}
this (Element element)
{
components[] = element;
}
So, while the mistake was mine, this should be an ambiguous
overload error at compile-time, instead of a linker error.
Comment #1 by nick — 2019-02-07T11:32:04Z
It's not clear what the original code and the problem with the linker was. Just to check, without the constraint, this code is fine:
struct S{
this (Elements...)(Elements elements){...}
this (Element element){...}
}
S s = S(Element.init);
The above call matches this(Element), the constructor template is less specialized.
Comment #2 by razvan.nitu1305 — 2022-08-25T14:39:37Z
This bug report contains insufficient information to see what the issue is. As such I will close this as MOVED, but if new information arises, feel free to reopen.