diff --git a/src/Generator/Passes/HandleDefaultParamValuesPass.cs b/src/Generator/Passes/HandleDefaultParamValuesPass.cs index db7c6fd0..b904e29f 100644 --- a/src/Generator/Passes/HandleDefaultParamValuesPass.cs +++ b/src/Generator/Passes/HandleDefaultParamValuesPass.cs @@ -59,7 +59,9 @@ namespace CppSharp.Passes { var desugared = type.Desugar(); - if ((!Driver.Options.MarshalCharAsManagedChar && + // constants are obtained through dynamic calls at present so they are not compile-time values in target languages + if (expression.Declaration is Variable || + (!Driver.Options.MarshalCharAsManagedChar && desugared.IsPrimitiveType(PrimitiveType.UChar)) || type.IsPrimitiveTypeConvertibleToRef()) return null; diff --git a/tests/CSharp/CSharp.Tests.cs b/tests/CSharp/CSharp.Tests.cs index 42ceed1f..feadad6f 100644 --- a/tests/CSharp/CSharp.Tests.cs +++ b/tests/CSharp/CSharp.Tests.cs @@ -211,7 +211,8 @@ public unsafe class CSharpTests : GeneratorTestFixture methodsWithDefaultValues.DefaultWithFunctionCall(); methodsWithDefaultValues.DefaultWithPropertyCall(); methodsWithDefaultValues.DefaultWithGetPropertyCall(); - methodsWithDefaultValues.DefaultWithStringConstant(); + methodsWithDefaultValues.DefaultWithIndirectStringConstant(); + methodsWithDefaultValues.DefaultWithDirectIntConstant(); } } diff --git a/tests/CSharp/CSharp.cpp b/tests/CSharp/CSharp.cpp index e45490b6..2a2e451a 100644 --- a/tests/CSharp/CSharp.cpp +++ b/tests/CSharp/CSharp.cpp @@ -414,6 +414,7 @@ MethodsWithDefaultValues::QMargins::QMargins(int left, int top, int right, int b } char* MethodsWithDefaultValues::stringConstant = "test"; +int MethodsWithDefaultValues::intConstant = 5; MethodsWithDefaultValues::MethodsWithDefaultValues(Foo foo) { @@ -570,7 +571,11 @@ void MethodsWithDefaultValues::defaultWithGetPropertyCall(int f) { } -void MethodsWithDefaultValues::defaultWithStringConstant(const Foo& arg) +void MethodsWithDefaultValues::defaultWithIndirectStringConstant(const Foo& arg) +{ +} + +void MethodsWithDefaultValues::defaultWithDirectIntConstant(int arg) { } diff --git a/tests/CSharp/CSharp.h b/tests/CSharp/CSharp.h index a49c120d..8e042754 100644 --- a/tests/CSharp/CSharp.h +++ b/tests/CSharp/CSharp.h @@ -355,6 +355,7 @@ public: }; static char* stringConstant; + static int intConstant; MethodsWithDefaultValues(Foo foo = Foo()); MethodsWithDefaultValues(int a); @@ -398,7 +399,8 @@ public: void defaultWithFunctionCall(int f = Foo::makeFunctionCall()); void defaultWithPropertyCall(int f = Foo::propertyCall()); void defaultWithGetPropertyCall(int f = Foo::getGetPropertyCall()); - void defaultWithStringConstant(const Foo& arg = Foo(stringConstant)); + void defaultWithIndirectStringConstant(const Foo& arg = Foo(stringConstant)); + void defaultWithDirectIntConstant(int arg = intConstant); int getA(); private: Foo m_foo;