www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 19179] New: extern(C++) small-struct by-val uses wrong ABI

https://issues.dlang.org/show_bug.cgi?id=19179

          Issue ID: 19179
           Summary: extern(C++) small-struct by-val uses wrong ABI
           Product: D
           Version: D2
          Hardware: All
                OS: Windows
            Status: NEW
          Severity: blocker
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: turkeyman gmail.com

test.d
------

import core.stdc.stdio;

extern(C++) struct SmallStruct { int x = 10, y = 20; }

SmallStruct test_small(SmallStruct s)
{
        printf("%d %d\n", s.x, s.y); // prints: invalid memory
        return s;
}
void test_small_noret(SmallStruct s)
{
        printf("%d %d\n", s.x, s.y); // prints: 10 20
}


test.cpp
--------

struct SmallStruct { int x = 10, y = 20; };

SmallStruct test_small(SmallStruct);
void test_small_noret(SmallStruct);

void main()
{
        test_small(SmallStruct());
        test_small_noret(SmallStruct());
}



Tested with VS2015 - x86 and x64
Note: if you add one more `int` to the struct, this code works as expected.

--
Aug 19 2018