This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] C FE: use correct location range for static assertions


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&regrtested 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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]