diff options
author | Steven Bosscher <stevenb@suse.de> | 2004-07-20 09:57:13 +0000 |
---|---|---|
committer | Steven Bosscher <steven@gcc.gnu.org> | 2004-07-20 09:57:13 +0000 |
commit | a6c0a76c5f9eb216b5f08ffc4624a6d039ca3977 (patch) | |
tree | 134a4370313a4f575f6aa704b0deb37112d1b859 /gcc/testsuite/gcc.dg/switch-warn-1.c | |
parent | 5794581363d5c74938f0e200b4c899a5b26229e9 (diff) | |
download | gcc-a6c0a76c5f9eb216b5f08ffc4624a6d039ca3977.zip gcc-a6c0a76c5f9eb216b5f08ffc4624a6d039ca3977.tar.gz gcc-a6c0a76c5f9eb216b5f08ffc4624a6d039ca3977.tar.bz2 |
c-common.h (check_case_value): Remove prototype.
* c-common.h (check_case_value): Remove prototype.
(c_add_case_label): Adjust prototype.
* c-common.c (check_case_value): Make static.
(check_case_bounds): New function.
(c_add_case_label): Use it. Take new argument orig_type.
* c-typeck.c (struct c_switch): New orig_type field.
(c_start_case): Set it.
(do_case): Pass it to c_add_case_label.
* expr.c (expand_expr_real_1): Don't warn for out-of-bounds
cases from here. Add the labels in reverse order.
* stmt.c (struct case_node): Adjust comment. Remove balance field.
(add_case_node): Return nothing, don't check for duplicate cases.
Insert new case nodes in a list, not in an AVL tree.
(expand_end_case_type): Don't turn a case tree into a case list.
(case_tree2list): Remove.
* tree.h (add_case_node): Adjust prototype.
cp/
* cp-tree.h (struct lang_decl_flags): Unify the template_info and
thunk_alias, and the access and virtual_offset fields.
(THUNK_VIRTUAL_OFFSET, THUNK_ALIAS): Adjust.
* decl.c (finish_case_label): Update c_add_case_node call.
testsuite/
* testsuite/gcc.dg/switch-warn-1.c: New test.
* testsuite/gcc.dg/switch-warn-2.c: New test.
* gcc.c-torture/compile/pr14730.c: Update
From-SVN: r84947
Diffstat (limited to 'gcc/testsuite/gcc.dg/switch-warn-1.c')
-rw-r--r-- | gcc/testsuite/gcc.dg/switch-warn-1.c | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/gcc/testsuite/gcc.dg/switch-warn-1.c b/gcc/testsuite/gcc.dg/switch-warn-1.c new file mode 100644 index 0000000..d98bfa8 --- /dev/null +++ b/gcc/testsuite/gcc.dg/switch-warn-1.c @@ -0,0 +1,44 @@ +/* { dg-do run } */ +/* { dg-options "-O0" } */ + +/* Check that out-of-bounds case warnings work in the case that the + testing expression is promoted. */ +int +foo1 (unsigned char i) +{ + switch (i) + { + case -1: /* { dg-warning "case label value is less than minimum value for type" } */ + return 1; + case 256: /* { dg-warning "case label value exceeds maximum value for type" } */ + return 2; + default: + return 3; + } +} + +/* Like above, but for case ranges that need to be satured. */ +int +foo2 (unsigned char i) +{ + switch (i) + { + case -1 ... 1: /* { dg-warning "lower value in case label range less than minimum value for type" } */ + return 1; + case 254 ... 256: /* { dg-warning "upper value in case label range exceeds maximum value for type" } */ + return 2; + default: + return 3; + } +} + +int +main (void) +{ + if (foo1 (10) != 3) + abort (); + if (foo2 (10) != 3) + abort (); + exit (0); +} + |