diff --git a/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitDecl.cs b/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitDecl.cs index cbf3f8c9..efe8e0a9 100644 --- a/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitDecl.cs +++ b/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitDecl.cs @@ -2913,22 +2913,16 @@ bool IsConstant(Expr initExpr) // case CX_StmtClass.CX_StmtClass_BuiltinBitCastExpr: case CX_StmtClass.CX_StmtClass_CStyleCastExpr: + case CX_StmtClass.CX_StmtClass_CXXStaticCastExpr: + case CX_StmtClass.CX_StmtClass_CXXFunctionalCastExpr: { - var cStyleCastExpr = (CStyleCastExpr)initExpr; - return IsConstant(cStyleCastExpr.SubExprAsWritten); + var cxxFunctionalCastExpr = (ExplicitCastExpr)initExpr; + return IsConstant(cxxFunctionalCastExpr.SubExprAsWritten); } - // case CX_StmtClass.CX_StmtClass_CXXFunctionalCastExpr: // case CX_StmtClass.CX_StmtClass_CXXConstCastExpr: // case CX_StmtClass.CX_StmtClass_CXXDynamicCastExpr: // case CX_StmtClass.CX_StmtClass_CXXReinterpretCastExpr: - - case CX_StmtClass.CX_StmtClass_CXXStaticCastExpr: - { - var cxxStaticCastExpr = (CXXStaticCastExpr)initExpr; - return IsConstant(cxxStaticCastExpr.SubExprAsWritten); - } - // case CX_StmtClass.CX_StmtClass_ObjCBridgedCastExpr: case CX_StmtClass.CX_StmtClass_ImplicitCastExpr: diff --git a/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.cs b/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.cs index 6ff0549a..99d0ddcc 100644 --- a/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.cs +++ b/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.cs @@ -2617,6 +2617,7 @@ private bool IsUnchecked(string targetTypeName, Stmt stmt) case CX_StmtClass.CX_StmtClass_CStyleCastExpr: case CX_StmtClass.CX_StmtClass_CXXStaticCastExpr: + case CX_StmtClass.CX_StmtClass_CXXFunctionalCastExpr: { var explicitCastExpr = (ExplicitCastExpr)stmt; var explicitCastExprTypeName = GetRemappedTypeName(explicitCastExpr, context: null, explicitCastExpr.Type, out _); @@ -2626,7 +2627,6 @@ private bool IsUnchecked(string targetTypeName, Stmt stmt) || (IsUnsigned(targetTypeName) != IsUnsigned(explicitCastExprTypeName)); } - // case CX_StmtClass.CX_StmtClass_CXXFunctionalCastExpr: // case CX_StmtClass.CX_StmtClass_CXXConstCastExpr: // case CX_StmtClass.CX_StmtClass_CXXDynamicCastExpr: // case CX_StmtClass.CX_StmtClass_CXXReinterpretCastExpr: diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/VarDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/VarDeclarationTest.cs index 1cb83127..bb7a1128 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/VarDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/VarDeclarationTest.cs @@ -240,6 +240,26 @@ public static partial class Methods await ValidateGeneratedBindingsAsync(inputContents, expectedOutputContents); } + + [Fact] + public async Task UncheckedFunctionLikeCastMacroTest() + { + var inputContents = $@"#define MyMacro1 unsigned(-1)"; + + var expectedOutputContents = $@"namespace ClangSharp.Test +{{ + public static partial class Methods + {{ + [NativeTypeName(""#define MyMacro1 unsigned(-1)"")] + public const uint MyMacro1 = unchecked((uint)(-1)); + }} +}} +"; + + await ValidateGeneratedBindingsAsync(inputContents, expectedOutputContents); + } + + [Fact] public async Task UncheckedConversionMacroTest2() {