diff --git a/src/Generator/Generators/CLI/CLIMarshal.cs b/src/Generator/Generators/CLI/CLIMarshal.cs index a1f5d75f..ae211ec5 100644 --- a/src/Generator/Generators/CLI/CLIMarshal.cs +++ b/src/Generator/Generators/CLI/CLIMarshal.cs @@ -90,12 +90,16 @@ namespace CppSharp.Generators.CLI } if (pointee.IsPrimitiveType(out primitive)) - { + { + var returnVarName = Context.ReturnVarName; + if (quals.IsConst != Context.ReturnType.Qualifiers.IsConst) + returnVarName = string.Format("const_cast<{0}>({1})", + Context.ReturnType, Context.ReturnVarName); if (pointer.Pointee is TypedefType) - Context.Return.Write("reinterpret_cast<{0}>({1})", pointer, - Context.ReturnVarName); - else - Context.Return.Write(Context.ReturnVarName); + Context.Return.Write("reinterpret_cast<{0}>({1})", pointer, + returnVarName); + else + Context.Return.Write(returnVarName); return true; } diff --git a/tests/Basic/Basic.h b/tests/Basic/Basic.h index 7a8162bb..4a836261 100644 --- a/tests/Basic/Basic.h +++ b/tests/Basic/Basic.h @@ -21,8 +21,8 @@ public: // Not properly handled yet - ignore float nested_array[2][2]; // Primitive pointer types - int* SomePointer; - int** SomePointerPointer; + const int* SomePointer; + const int** SomePointerPointer; }; struct DLL_API Bar