This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] C FE: use correct location range for static assertions
- From: Marek Polacek <polacek at redhat dot com>
- To: David Malcolm <dmalcolm at redhat dot com>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Tue, 15 Dec 2015 23:50:37 +0100
- Subject: Re: [PATCH] C FE: use correct location range for static assertions
- Authentication-results: sourceware.org; auth=none
- References: <1450198309-5325-1-git-send-email-dmalcolm at redhat dot com>
On Tue, Dec 15, 2015 at 11:51:49AM -0500, David Malcolm wrote:
> When issuing diagnostics for _Static_assert, we currently ignore the
> location/range of the asserted expression, and instead use the
> location/range of the first token within it, which can be
> incorrect for compound expressions:
>
> error: expression in static assertion is not constant
> _Static_assert (param > 0, "message");
> ^~~~~
>
> This patch changes things to use EXPR_LOC_OR_LOC, so we use the
> location/range of the expression if it has one, falling back to the old
> behavior if it doesn't, giving:
>
> error: expression in static assertion is not constant
> _Static_assert (param > 0, "message");
> ~~~~~~^~~
>
> Successfully bootstrapped®rtested on x86_64-pc-linux-gnu
>
> OK for trunk in stage 3?
>
> [a much earlier version of this was posted as part of:
> "[PATCH 16/22] C/C++ frontend: use tree ranges in various diagnostics"
> https://gcc.gnu.org/ml/gcc-patches/2015-09/msg00745.html
> but this patch bears no resemblence apart from the testcase, due to
> changes in representation]
>
> 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.
Looks ok to me.
Marek