aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorDavid Malcolm <dmalcolm@redhat.com>2015-12-16 17:25:45 +0000
committerDavid Malcolm <dmalcolm@gcc.gnu.org>2015-12-16 17:25:45 +0000
commit8062bca66dc0acfaf7b5d2659ee5ca4381fea9e8 (patch)
tree1ee547d74e7d3d0c1c961fb845833707dd113d75 /gcc
parent040b0c97c4d2cccdc3f80f7ad81ceb88e6794744 (diff)
downloadgcc-8062bca66dc0acfaf7b5d2659ee5ca4381fea9e8.zip
gcc-8062bca66dc0acfaf7b5d2659ee5ca4381fea9e8.tar.gz
gcc-8062bca66dc0acfaf7b5d2659ee5ca4381fea9e8.tar.bz2
C FE: use correct location range for static assertions
gcc/c/ChangeLog: * c-parser.c (c_parser_static_assert_declaration_no_semi): Use the expression location, falling back on the first token location, rather than always using the latter. gcc/testsuite/ChangeLog: * gcc.dg/diagnostic-range-static-assert.c: New test case. From-SVN: r231704
Diffstat (limited to 'gcc')
-rw-r--r--gcc/c/ChangeLog6
-rw-r--r--gcc/c/c-parser.c3
-rw-r--r--gcc/testsuite/ChangeLog4
-rw-r--r--gcc/testsuite/gcc.dg/diagnostic-range-static-assert.c24
4 files changed, 36 insertions, 1 deletions
diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog
index fd1c707..3ed1326 100644
--- a/gcc/c/ChangeLog
+++ b/gcc/c/ChangeLog
@@ -1,3 +1,9 @@
+2015-12-16 David Malcolm <dmalcolm@redhat.com>
+
+ * c-parser.c (c_parser_static_assert_declaration_no_semi): Use the
+ expression location, falling back on the first token location,
+ rather than always using the latter.
+
2015-12-16 Marek Polacek <polacek@redhat.com>
PR c/64637
diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c
index 124c30b..5c32f45 100644
--- a/gcc/c/c-parser.c
+++ b/gcc/c/c-parser.c
@@ -2097,8 +2097,9 @@ c_parser_static_assert_declaration_no_semi (c_parser *parser)
c_parser_consume_token (parser);
if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
return;
- value_loc = c_parser_peek_token (parser)->location;
+ location_t value_tok_loc = c_parser_peek_token (parser)->location;
value = c_parser_expr_no_commas (parser, NULL).value;
+ value_loc = EXPR_LOC_OR_LOC (value, value_tok_loc);
parser->lex_untranslated_string = true;
if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
{
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 7a66b14..adfb4e0 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,7 @@
+2015-12-16 David Malcolm <dmalcolm@redhat.com>
+
+ * gcc.dg/diagnostic-range-static-assert.c: New test case.
+
2015-12-16 Marek Polacek <polacek@redhat.com>
PR c/64637
diff --git a/gcc/testsuite/gcc.dg/diagnostic-range-static-assert.c b/gcc/testsuite/gcc.dg/diagnostic-range-static-assert.c
new file mode 100644
index 0000000..6f75476
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/diagnostic-range-static-assert.c
@@ -0,0 +1,24 @@
+/* { dg-options "-fdiagnostics-show-caret" } */
+
+void test_nonconst_static_assert (int param)
+{
+ int local = 0;
+
+ _Static_assert (param > 0, "message"); /* { dg-error "expression in static assertion is not constant" } */
+/* { dg-begin-multiline-output "" }
+ _Static_assert (param > 0, "message");
+ ~~~~~~^~~
+{ dg-end-multiline-output "" } */
+
+ _Static_assert (param, "message"); /* { dg-error "expression in static assertion is not constant" } */
+/* { dg-begin-multiline-output "" }
+ _Static_assert (param, "message");
+ ^~~~~
+{ dg-end-multiline-output "" } */
+
+ _Static_assert (local, "message"); /* { dg-error "expression in static assertion is not constant" } */
+/* { dg-begin-multiline-output "" }
+ _Static_assert (local, "message");
+ ^~~~~
+{ dg-end-multiline-output "" } */
+}