Skip to content

Commit 0e963aa

Browse files
committed
Generate valid C# for default args: typedefed refs to enums assigned empty ctors
Signed-off-by: Dimitar Dobrev <[email protected]>
1 parent 15a5548 commit 0e963aa

File tree

5 files changed

+13
-4
lines changed

5 files changed

+13
-4
lines changed

src/Generator/Passes/ExpressionHelper.cs

+3-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ internal class ExpressionHelper
1919
private static readonly Regex regexDoubleColon = new Regex(@"\w+::", RegexOptions.Compiled);
2020
private static readonly Regex regexName = new Regex(@"(\w+)", RegexOptions.Compiled);
2121

22-
public static bool? PrintExpression(BindingContext context, Function function, Type type, ExpressionObsolete expression, bool allowDefaultLiteral, ref string result)
22+
public static bool? PrintExpression(BindingContext context, Function function, Type type,
23+
ExpressionObsolete expression, bool allowDefaultLiteral, ref string result)
2324
{
2425
var desugared = type.Desugar();
2526

@@ -226,7 +227,7 @@ private static bool CheckForDefaultPointer(BindingContext context, Type desugare
226227
private static bool? CheckForDefaultConstruct(BindingContext context, Type desugared, ExpressionObsolete expression,
227228
ref string result)
228229
{
229-
var type = desugared.GetFinalPointee() ?? desugared;
230+
var type = (desugared.GetFinalPointee() ?? desugared).Desugar();
230231

231232
Class decl;
232233
if (!type.TryGetClass(out decl))

tests/CSharp/CSharp.Tests.cs

+1
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,7 @@ public void TestDefaultArguments()
318318
Assert.That(methodsWithDefaultValues.DefaultMappedToEnum(), Is.EqualTo(Flags.Flag3));
319319
methodsWithDefaultValues.DefaultMappedToZeroEnum();
320320
methodsWithDefaultValues.DefaultMappedToEnumAssignedWithCtor();
321+
methodsWithDefaultValues.DefaultTypedefMappedToEnumRefAssignedWithCtor();
321322
methodsWithDefaultValues.DefaultZeroMappedToEnumAssignedWithCtor();
322323
Assert.That(methodsWithDefaultValues.DefaultImplicitCtorInt().Priv, Is.EqualTo(0));
323324
methodsWithDefaultValues.DefaultImplicitCtorChar();

tests/CSharp/CSharp.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -713,6 +713,10 @@ void MethodsWithDefaultValues::defaultMappedToEnumAssignedWithCtor(QFlags<Flags>
713713
{
714714
}
715715

716+
void MethodsWithDefaultValues::defaultTypedefMappedToEnumRefAssignedWithCtor(const TypedefedFlags& qFlags)
717+
{
718+
}
719+
716720
void MethodsWithDefaultValues::defaultZeroMappedToEnumAssignedWithCtor(DefaultZeroMappedToEnum defaultZeroMappedToEnum)
717721
{
718722
}

tests/CSharp/CSharp.h

+2
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,8 @@ class DLL_API MethodsWithDefaultValues : public Quux
452452
QFlags<Flags> defaultMappedToEnum(const QFlags<Flags>& qFlags = Flags::Flag3);
453453
void defaultMappedToZeroEnum(QFlags<Flags> qFlags = 0);
454454
void defaultMappedToEnumAssignedWithCtor(QFlags<Flags> qFlags = QFlags<Flags>());
455+
typedef QFlags<Flags> TypedefedFlags;
456+
void defaultTypedefMappedToEnumRefAssignedWithCtor(const TypedefedFlags& qFlags = TypedefedFlags());
455457
void defaultZeroMappedToEnumAssignedWithCtor(DefaultZeroMappedToEnum defaultZeroMappedToEnum = DefaultZeroMappedToEnum());
456458
Quux defaultImplicitCtorInt(Quux arg = 0);
457459
void defaultImplicitCtorChar(Quux arg = 'a');

tests/CSharp/CSharpTemplates.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -698,10 +698,11 @@ template <typename T>
698698
class QFlags
699699
{
700700
typedef int Int;
701-
typedef int (*Zero);
701+
struct Private;
702+
typedef int (Private::*Zero);
702703
public:
703704
QFlags(T t);
704-
QFlags(Zero = 0);
705+
QFlags(Zero = nullptr);
705706
operator Int();
706707
private:
707708
int flag;

0 commit comments

Comments
 (0)