diff --git a/src/Generator/Passes/HandleDefaultParamValuesPass.cs b/src/Generator/Passes/HandleDefaultParamValuesPass.cs index 4613cff1..40d51cf7 100644 --- a/src/Generator/Passes/HandleDefaultParamValuesPass.cs +++ b/src/Generator/Passes/HandleDefaultParamValuesPass.cs @@ -73,6 +73,11 @@ namespace CppSharp.Passes if (defaultConstruct != false) return defaultConstruct; + return CheckForSimpleExpressions(expression, ref result, desugared); + } + + private bool CheckForSimpleExpressions(Expression expression, ref string result, Type desugared) + { return CheckFloatSyntax(desugared, expression, ref result) || CheckForBinaryOperator(desugared, expression, ref result) || CheckForEnumValue(desugared, expression, ref result) || @@ -106,7 +111,7 @@ namespace CppSharp.Passes return true; } - private bool? CheckForDefaultConstruct(Type desugared, Statement statement, + private bool? CheckForDefaultConstruct(Type desugared, Expression expression, ref string result) { var type = desugared.GetFinalPointee() ?? desugared; @@ -115,7 +120,7 @@ namespace CppSharp.Passes if (!type.TryGetClass(out decl)) return false; - var ctor = statement as CXXConstructExpr; + var ctor = expression as CXXConstructExpr; TypeMap typeMap; @@ -147,12 +152,15 @@ namespace CppSharp.Passes } if (ctor == null) + { + CheckForSimpleExpressions(expression, ref result, desugared); return decl.IsValueType ? (bool?) false : null; + } - var method = (Method) statement.Declaration; + var method = (Method) expression.Declaration; var expressionSupported = decl.IsValueType && method.Parameters.Count == 0; - if (statement.String.Contains('(')) + if (expression.String.Contains('(')) { var argsBuilder = new StringBuilder("new "); argsBuilder.Append(typePrinterResult); @@ -177,7 +185,7 @@ namespace CppSharp.Passes var paramType = method.Parameters[0].Type.SkipPointerRefs().Desugar(); Enumeration @enum; if (paramType.TryGetEnum(out @enum)) - result = TranslateEnumExpression(method, paramType, statement.String); + result = TranslateEnumExpression(method, paramType, expression.String); } } return expressionSupported ? true : (bool?) null; diff --git a/tests/CSharp/CSharp.Tests.cs b/tests/CSharp/CSharp.Tests.cs index 7ba599dd..7e258788 100644 --- a/tests/CSharp/CSharp.Tests.cs +++ b/tests/CSharp/CSharp.Tests.cs @@ -189,6 +189,7 @@ public class CSharpTests : GeneratorTestFixture methodsWithDefaultValues.DefaultImplicitCtorInt(); methodsWithDefaultValues.DefaultImplicitCtorChar(); methodsWithDefaultValues.DefaultImplicitCtorFoo(); + methodsWithDefaultValues.DefaultImplicitCtorEnum(); methodsWithDefaultValues.DefaultIntWithLongExpression(); methodsWithDefaultValues.DefaultRefTypeEnumImplicitCtor(); methodsWithDefaultValues.Rotate4x4Matrix(0, 0, 0); diff --git a/tests/CSharp/CSharp.cpp b/tests/CSharp/CSharp.cpp index fadba6da..2340b014 100644 --- a/tests/CSharp/CSharp.cpp +++ b/tests/CSharp/CSharp.cpp @@ -181,6 +181,10 @@ ForceCreationOfInterface::ForceCreationOfInterface() { } +Baz::Baz(Bar::Items item) +{ +} + int Baz::takesQux(const Qux& qux) { return qux.farAwayFunc(); @@ -463,6 +467,10 @@ void MethodsWithDefaultValues::defaultImplicitCtorFoo(Quux arg) { } +void MethodsWithDefaultValues::defaultImplicitCtorEnum(Baz arg) +{ +} + void MethodsWithDefaultValues::defaultIntWithLongExpression(unsigned int i) { } diff --git a/tests/CSharp/CSharp.h b/tests/CSharp/CSharp.h index 0249b787..6c44f668 100644 --- a/tests/CSharp/CSharp.h +++ b/tests/CSharp/CSharp.h @@ -98,6 +98,7 @@ public: class NestedDerived : public NestedBase1, public NestedBase2 {}; Baz(); + Baz(Bar::Items item); int P; @@ -358,6 +359,11 @@ public: void defaultImplicitCtorInt(Quux arg = 0); void defaultImplicitCtorChar(Quux arg = 'a'); void defaultImplicitCtorFoo(Quux arg = Foo()); + // this looks the same test as 'defaultRefTypeEnumImplicitCtor' two lines below + // however, Clang considers them different + // in this case the arg is a MaterializeTemporaryExpr, in the other not + // I cannot see the difference but it's there so we need both tests + void defaultImplicitCtorEnum(Baz arg = Bar::Item1); void defaultIntWithLongExpression(unsigned int i = DEFAULT_INT); void defaultRefTypeEnumImplicitCtor(const QColor &fillColor = Qt::white); void rotate4x4Matrix(float angle, float x, float y, float z = 0.0f);