[Issue 23059] New: importC: calls to D template functions don't convert some argument types
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Mon Apr 25 00:35:47 UTC 2022
https://issues.dlang.org/show_bug.cgi?id=23059
Issue ID: 23059
Summary: importC: calls to D template functions don't convert
some argument types
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Keywords: ImportC
Severity: normal
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: duser at neet.fi
CC: duser at neet.fi
// dmodule.di
void my_builtin_bswap16()(short x){}
void my_atomic_store_n(T)(T* ptr, T val, int memorder){}
// main.c
__import dmodule;
int main()
{
int x;
// Error: none of the overloads are callable using argument types
`!()(int)`
// same with other bswap builtins when passed a bigger type than they
expect
my_builtin_bswap16(x);
//my_builtin_bswap16((short)x); // works
int *p;
// Error: none of the overloads are callable using argument types
`!()(int**, int, int)`
my_atomic_store_n(&p, 0, 0);
//my_atomic_store_n(&p, (int *)0, 0); // works
}
1. affects __builtin_bswapN() in druntime (when passed a larger type than they
expect): the variable isn't converted to the smaller type in the call, so the
template fails to match
2. affects my implementation of some gcc atomic builtins: when T is inferred as
a pointer type by the first argument, passing "0" (or a number variable) as the
second argument doesn't convert it to a pointer type
both are different from what you'd get when calling a non-templated C or D
function, or the equivalent builtins in gcc
it would be nice if these worked more like in C so the templates didn't need to
implement the conversions themselves
--
More information about the Digitalmars-d-bugs
mailing list