From 3de896cebebbdb35d179d17133ee53e505b1f0a8 Mon Sep 17 00:00:00 2001 From: Xavier Leroy Date: Thu, 24 May 2018 20:07:43 +0200 Subject: Reject "e1, e2" as a compile-time constant expression This is what ISO C99 says, even though C++ and some C compilers accept it. --- cparser/Ceval.ml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'cparser/Ceval.ml') diff --git a/cparser/Ceval.ml b/cparser/Ceval.ml index f479ad5c..6247254f 100644 --- a/cparser/Ceval.ml +++ b/cparser/Ceval.ml @@ -217,8 +217,6 @@ let binop env op tyop tyres ty1 v1 ty2 v2 = comparison env (<=) None tyop v1 v2 | Oge -> comparison env (>=) None tyop v1 v2 - | Ocomma -> - v2 | Ologand -> if boolean_value v1 then if boolean_value v2 then I 1L else I 0L @@ -315,10 +313,8 @@ and is_constant_expr env e = | Oadd | Osub | Omul | Odiv | Omod | Oand | Oor | Oxor | Oshl | Oshr | Oeq | One | Olt | Ogt | Ole | Oge - | Ocomma | Ologand | Ologor -> + | Ologand | Ologor -> is_constant_expr env e1 && is_constant_expr env e2 - (* ISO C99 says that constant expressions shall not contain comma - operators. However, clang accepts them, and they are harmless. *) | Oindex -> is_constant_rval_of_lval env e | Oassign @@ -326,6 +322,10 @@ and is_constant_expr env e = | Oand_assign | Oor_assign | Oxor_assign | Oshl_assign | Oshr_assign -> false (* constant expressions shall not contain assignments *) + | Ocomma -> + false + (* some C compilers accept "e1, e2" as a constant expression. + But this is not standard ISO C. *) end | EConditional(e1, e2, e3) -> is_constant_expr env e1 && is_constant_expr env e2 -- cgit