Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
@ -181,6 +181,8 @@ namespace CppSharp.AST
public bool IsInterface => Type == ClassType.Interface;
public bool HasUnionFields { get; set; }
public bool IsAbstractImpl
{
get { return Methods.Any(m => m.SynthKind == FunctionSynthKind.AbstractImplCall); }
@ -792,7 +792,7 @@ namespace CppSharp.Generators.CSharp
private bool CanUseSequentialLayout(Class @class)
if (@class.IsUnion)
if (@class.IsUnion || @class.HasUnionFields)
return false;
foreach (var field in @class.Fields)
@ -31,6 +31,8 @@ namespace CppSharp.Passes
ReplaceField(@class, i, fieldType);
fieldType.Fields.Clear();
fieldType.ExplicitlyIgnore();
if (fieldType.IsUnion)
@class.HasUnionFields = true;
}
if (@class.Layout == null)
@ -389,6 +389,11 @@ public class CommonTests
nestedPublic.J = 5;
Assert.That(nestedPublic.L, Is.EqualTo(5));
Assert.That(nestedPublic.G, Is.Not.EqualTo(0));
using (var nestedUnionWithNested = new NestedUnionWithNested())
nestedUnionWithNested.NestedField1 = 50;
Assert.That(nestedUnionWithNested.UnionField, Is.EqualTo(50));
[Test]
@ -1333,6 +1333,19 @@ public:
static ReturnByValueWithReturnParam generate();
};
struct DLL_API NestedUnionWithNested
union
struct
int nestedField1;
int nestedField2;
int unionField;
template<typename T> void TemplatedFunction(T type)