Skip to content

Commit 79717cb

Browse files
Merge pull request #515 from tannergooding/main
Ensure a cast is inserted for enum constant decls involving an implicit sign change
2 parents c57d404 + 72268b2 commit 79717cb

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitDecl.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
using static ClangSharp.Interop.CXUnaryOperatorKind;
1919
using static ClangSharp.Interop.CXEvalResultKind;
2020
using static ClangSharp.Interop.CXTypeKind;
21-
using ClangSharp.Interop;
2221

2322
namespace ClangSharp;
2423

sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6463,7 +6463,19 @@ private void UncheckStmt(string targetTypeName, Stmt stmt)
64636463
{
64646464
_outputBuilder.BeginUnchecked();
64656465

6466-
var needsCast = IsStmtAsWritten<IntegerLiteral>(stmt, out _, removeParens: true) && (stmt.DeclContext is EnumDecl);
6466+
var needsCast = false;
6467+
6468+
if (stmt.DeclContext is EnumDecl)
6469+
{
6470+
if (IsStmtAsWritten<IntegerLiteral>(stmt, out _, removeParens: true))
6471+
{
6472+
needsCast = true;
6473+
}
6474+
else if (stmt is ImplicitCastExpr)
6475+
{
6476+
needsCast = true;
6477+
}
6478+
}
64676479

64686480
if (IsStmtAsWritten<UnaryExprOrTypeTraitExpr>(stmt, out var unaryExprOrTypeTraitExpr, removeParens: true) && ((CurrentContext.Cursor is VarDecl) || IsPrevContextDecl<VarDecl>(out _, out _)))
64696481
{

0 commit comments

Comments
 (0)