@@ -1021,10 +1021,16 @@ final class CParser(AST) : Parser!AST
1021
1021
{
1022
1022
if (token.value == TOK .leftParenthesis)
1023
1023
{
1024
+ // printf("cparseCastExp()\n");
1024
1025
auto tk = peek(&token);
1025
- if (tk.value == TOK .identifier &&
1026
- ! isTypedef(tk.ident) &&
1027
- peek(tk).value == TOK .rightParenthesis)
1026
+ bool iscast;
1027
+ bool isexp;
1028
+ if (tk.value == TOK .identifier)
1029
+ {
1030
+ iscast = isTypedef(tk.ident);
1031
+ isexp = ! iscast;
1032
+ }
1033
+ if (isexp)
1028
1034
{
1029
1035
// ( identifier ) is an expression
1030
1036
return cparseUnaryExp ();
@@ -1050,10 +1056,18 @@ final class CParser(AST) : Parser!AST
1050
1056
auto ce = new AST .CompoundLiteralExp(loc, t, ci);
1051
1057
return cparsePostfixOperators (ce);
1052
1058
}
1053
- else if (t.isTypeIdentifier() &&
1054
- ! isTypedef(t.isTypeIdentifier().ident) &&
1055
- token.value == TOK .leftParenthesis &&
1056
- ! isCastExpression(pt))
1059
+
1060
+ if (iscast)
1061
+ {
1062
+ // ( type-name ) cast-expression
1063
+ auto ce = cparseCastExp();
1064
+ return new AST .CastExp(loc, ce, t);
1065
+ }
1066
+
1067
+ if (t.isTypeIdentifier() &&
1068
+ isexp &&
1069
+ token.value == TOK .leftParenthesis &&
1070
+ ! isCastExpression(pt))
1057
1071
{
1058
1072
/* (t)(...)... might be a cast expression or a function call,
1059
1073
* with different grammars: a cast would be cparseCastExp(),
@@ -1067,12 +1081,10 @@ final class CParser(AST) : Parser!AST
1067
1081
AST .Expression e = new AST .CallExp(loc, ie, cparseArguments());
1068
1082
return cparsePostfixOperators (e);
1069
1083
}
1070
- else
1071
- {
1072
- // ( type-name ) cast-expression
1073
- auto ce = cparseCastExp();
1074
- return new AST .CastExp(loc, ce, t);
1075
- }
1084
+
1085
+ // ( type-name ) cast-expression
1086
+ auto ce = cparseCastExp();
1087
+ return new AST .CastExp(loc, ce, t);
1076
1088
}
1077
1089
}
1078
1090
return cparseUnaryExp ();
0 commit comments