Bug 20772 – va_arg doesn't work for structs with copy constructors

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
All
Creation time
2020-04-26T14:44:55Z
Last change time
2020-04-27T03:28:00Z
Keywords
pull
Assigned to
No Owner
Creator
Iain Buclaw

Comments

Comment #0 by ibuclaw — 2020-04-26T14:44:55Z
This prints: CopyConstructor = 64:0:2: ``` void testVariadic(T)(int nargs, ...) { printf(T.stringof ~ " = "); foreach(i; 0 .. nargs) { auto arg = va_arg!T(_argptr); static if (__traits(compiles, arg.value)) printf("%d", arg.value); //assert(arg.value == i); else assert(arg == T.init); printf(":"); } printf("\n"); } struct CopyConstructor { int value; this(int v) { this.value = v; } this(ref typeof(this) other) { this.value = other.value; } } void test4() { auto a0 = CopyConstructor(0); auto a1 = CopyConstructor(1); auto a2 = CopyConstructor(2); testVariadic!CopyConstructor(3, a0, a1, a2); } ```
Comment #1 by ibuclaw — 2020-04-26T15:00:20Z
I don't think this is a druntime bug. The compiler sets __argTypes differently for structs with cpctors vs. structs without: ``` static if (is(T U == __argTypes)) pragma(msg, T, " = ", U); ``` Prints: CopyConstructor = () NoCopyConstructor = (int)
Comment #2 by dlang-bot — 2020-04-26T22:44:44Z
@ibuclaw created dlang/dmd pull request #11065 "fix Issue 20771, 20772, disallow passing non-trivially copyable types as variadic arguments" fixing this issue: - fix Issue 20772 - va_arg doesn't work for structs with copy constructors https://github.com/dlang/dmd/pull/11065
Comment #3 by dlang-bot — 2020-04-27T03:28:00Z
dlang/dmd pull request #11065 "fix Issue 20771, 20772, 20775 disallow passing non-trivially copyable types as variadic arguments" was merged into master: - e8d157d3f9c9531c0812b6325ba2244abe6bc946 by Iain Buclaw: fix Issue 20772 - va_arg doesn't work for structs with copy constructors https://github.com/dlang/dmd/pull/11065