diff options
author | Marek Polacek <polacek@redhat.com> | 2014-08-03 12:23:03 +0000 |
---|---|---|
committer | Marek Polacek <mpolacek@gcc.gnu.org> | 2014-08-03 12:23:03 +0000 |
commit | 62e4eb3553f9ce05a6d08a1ef7d8e59f81aeeee6 (patch) | |
tree | 2584046c0dbb8332881d593db7cd195a717b30ce | |
parent | 87d5ce4856710235e9dbb728d3c05a8907e1c804 (diff) | |
download | gcc-62e4eb3553f9ce05a6d08a1ef7d8e59f81aeeee6.zip gcc-62e4eb3553f9ce05a6d08a1ef7d8e59f81aeeee6.tar.gz gcc-62e4eb3553f9ce05a6d08a1ef7d8e59f81aeeee6.tar.bz2 |
c-common.c (check_case_value): Add location_t parameter.
* c-common.c (check_case_value): Add location_t parameter. Use it.
(c_add_case_label): Pass loc to check_case_value.
* gcc.dg/case-bogus-1.c: New test.
From-SVN: r213525
-rw-r--r-- | gcc/c-family/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/c-family/c-common.c | 10 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 4 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/case-bogus-1.c | 8 |
4 files changed, 22 insertions, 5 deletions
diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index ff78859..b599627 100644 --- a/gcc/c-family/ChangeLog +++ b/gcc/c-family/ChangeLog @@ -1,3 +1,8 @@ +2014-08-03 Marek Polacek <polacek@redhat.com> + + * c-common.c (check_case_value): Add location_t parameter. Use it. + (c_add_case_label): Pass loc to check_case_value. + 2014-08-02 Trevor Saunders <tsaunders@mozilla.com> * cilk.c: Use hash_map instead of pointer_map. diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c index b2a053e..acc9a20 100644 --- a/gcc/c-family/c-common.c +++ b/gcc/c-family/c-common.c @@ -300,7 +300,7 @@ const struct fname_var_t fname_vars[] = struct visibility_flags visibility_options; static tree c_fully_fold_internal (tree expr, bool, bool *, bool *); -static tree check_case_value (tree); +static tree check_case_value (location_t, tree); static bool check_case_bounds (location_t, tree, tree, tree *, tree *); static tree handle_packed_attribute (tree *, tree, tree, int, bool *); @@ -3349,7 +3349,7 @@ verify_sequence_points (tree expr) /* Validate the expression after `case' and apply default promotions. */ static tree -check_case_value (tree value) +check_case_value (location_t loc, tree value) { if (value == NULL_TREE) return value; @@ -3359,7 +3359,7 @@ check_case_value (tree value) value = perform_integral_promotions (value); else if (value != error_mark_node) { - error ("case label does not reduce to an integer constant"); + error_at (loc, "case label does not reduce to an integer constant"); value = error_mark_node; } @@ -5993,14 +5993,14 @@ c_add_case_label (location_t loc, splay_tree cases, tree cond, tree orig_type, type = TREE_TYPE (cond); if (low_value) { - low_value = check_case_value (low_value); + low_value = check_case_value (loc, low_value); low_value = convert_and_check (loc, type, low_value); if (low_value == error_mark_node) goto error_out; } if (high_value) { - high_value = check_case_value (high_value); + high_value = check_case_value (loc, high_value); high_value = convert_and_check (loc, type, high_value); if (high_value == error_mark_node) goto error_out; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 68c4cf6..d18aed8 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2014-08-03 Marek Polacek <polacek@redhat.com> + + * gcc.dg/case-bogus-1.c: New test. + 2014-08-02 Paolo Carlini <paolo.carlini@oracle.com> PR c++/15339 diff --git a/gcc/testsuite/gcc.dg/case-bogus-1.c b/gcc/testsuite/gcc.dg/case-bogus-1.c new file mode 100644 index 0000000..548312e --- /dev/null +++ b/gcc/testsuite/gcc.dg/case-bogus-1.c @@ -0,0 +1,8 @@ +/* { dg-do compile } */ + +void +foo (int n) +{ + switch (n) + case 0: case 3: case 0.2: case 5:; /* { dg-error "21:case label does not reduce to an integer constant" } */ +} |