This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[4.5 C] Fix further constant expressions bug
- From: "Joseph S. Myers" <joseph at codesourcery dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Thu, 30 Oct 2008 01:38:14 +0000 (UTC)
- Subject: [4.5 C] Fix further constant expressions bug
I found a bug in c_parser_expr_list on c-4_5-branch leading to certain
invalid code not being diagnosed. I've applied this patch to that
branch to fix this bug; bootstrapped with no regressions on
i686-pc-linux-gnu.
2008-10-30 Joseph Myers <joseph@codesourcery.com>
* c-parser.c (c_parser_expr_list): Only fold second and subsequent
list entries if fold_p.
2008-10-30 Joseph Myers <joseph@codesourcery.com>
* gcc.dg/c90-const-expr-10.c, gcc.dg/c99-const-expr-10.c: Add more
tests.
Index: testsuite/gcc.dg/c90-const-expr-10.c
===================================================================
--- testsuite/gcc.dg/c90-const-expr-10.c (revision 141449)
+++ testsuite/gcc.dg/c90-const-expr-10.c (working copy)
@@ -20,3 +20,9 @@ h (void)
{
g ((__SIZE_TYPE__)(void *)0); /* { dg-error "without a cast" } */
}
+void g2 (int, void *); /* { dg-message "but argument is of type" } */
+void
+h2 (void)
+{
+ g2 (0, (__SIZE_TYPE__)(void *)0); /* { dg-error "without a cast" } */
+}
Index: testsuite/gcc.dg/c99-const-expr-10.c
===================================================================
--- testsuite/gcc.dg/c99-const-expr-10.c (revision 141449)
+++ testsuite/gcc.dg/c99-const-expr-10.c (working copy)
@@ -20,3 +20,9 @@ h (void)
{
g ((__SIZE_TYPE__)(void *)0); /* { dg-error "without a cast" } */
}
+void g2 (int, void *); /* { dg-message "but argument is of type" } */
+void
+h2 (void)
+{
+ g2 (0, (__SIZE_TYPE__)(void *)0); /* { dg-error "without a cast" } */
+}
Index: c-parser.c
===================================================================
--- c-parser.c (revision 141449)
+++ c-parser.c (working copy)
@@ -5738,7 +5738,8 @@ c_parser_expr_list (c_parser *parser, bo
expr = c_parser_expr_no_commas (parser, NULL);
if (convert_p)
expr = default_function_array_conversion (expr);
- expr.value = c_fully_fold (expr.value, false, NULL);
+ if (fold_p)
+ expr.value = c_fully_fold (expr.value, false, NULL);
cur = TREE_CHAIN (cur) = build_tree_list (NULL_TREE, expr.value);
}
return ret;
--
Joseph S. Myers
joseph@codesourcery.com