Bug 23308 – Can't resolve overload of varargs function if one parameter is the result of a ternary expression
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Windows
Creation time
2022-08-28T18:49:21Z
Last change time
2022-08-29T23:41:36Z
Assigned to
No Owner
Creator
KytoDragon
Comments
Comment #0 by kytodragon — 2022-08-28T18:49:21Z
This code:
```
void foo(string a) {}
void foo(A...)(A a) {}
void bar(bool condition, void* param) {
float s32;
foo(condition ? param : &s32);
}
```
results in the following error message:
```
test.d(8): Error: none of the overloads of `foo` are callable using argument types `(float*)`, candidates are:
test.d(2): `example.foo(string a)`
test.d(4): `foo(A...)(A a)`
```
If the condition is removed or if the values inside the ternary expression are cast to the same type, the error goes away.
```
foo(condition ? param : cast(void*)&s32);
```
The error message also references the wrong type, better seen in this example:
```
void foo(float* a) {}
void bar(bool condition, void* param) {
float s32;
foo(condition ? param : &s32);
}
```
```
test.d(5): Error: function `example.foo(float* a)` is not callable using argument types `(float*)`
test.d(5): cannot pass argument `condition ? param : & s32` of type `float*` to parameter `float* a`
```
Reproducible with all versions of DMD and LDC.
Comment #1 by dlang-bot — 2022-08-29T23:41:36Z
dlang/dmd pull request #14396 "Fix Issue 23308 - void* and T* not merged properly" was merged into master:
- e9534be7a390d622c4941c5b6cafef99745da74f by mhh:
Fix Issue 23308 - void* and T* not merged properly
https://github.com/dlang/dmd/pull/14396