Skip to content

Commit

Permalink
translate-c: detect parenthesized string literals
Browse files Browse the repository at this point in the history
  • Loading branch information
Vexu committed Dec 16, 2020
1 parent b3c1ced commit d3a57b9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/translate_c.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1797,6 +1797,10 @@ fn exprIsStringLiteral(expr: *const clang.Expr) bool {
const op_expr = @ptrCast(*const clang.UnaryOperator, expr).getSubExpr();
return exprIsStringLiteral(op_expr);
},
.ParenExprClass => {
const op_expr = @ptrCast(*const clang.ParenExpr, expr).getSubExpr();
return exprIsStringLiteral(op_expr);
},
else => return false,
}
}
Expand Down
7 changes: 7 additions & 0 deletions test/run_translated_c.zig
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ const tests = @import("tests.zig");
const nl = std.cstr.line_sep;

pub fn addCases(cases: *tests.RunTranslatedCContext) void {
cases.add("parenthesized string literal",
\\void foo(const char *s) {}
\\int main(void) {
\\ foo(("bar"));
\\}
, "");

cases.add("variable shadowing type type",
\\#include <stdlib.h>
\\int main() {
Expand Down

0 comments on commit d3a57b9

Please sign in to comment.