"error: static assertion failed: [...]" (was: [GCC Wiki] Update of "DiagnosticsGuidelines" by MartinSebor)
Manuel López-Ibáñez
lopezibanez@gmail.com
Thu Jul 14 02:46:00 GMT 2016
On 13/07/16 14:26, Thomas Schwinge wrote:
> Hi!
>
> I had recently noticed that given:
>
> #ifndef __cplusplus /* C */
> _Static_assert(0, "foo");
> #else /* C++ */
> static_assert(0, "foo");
> #endif
>
> ..., for C we diagnose:
>
> [...]:2:1: error: static assertion failed: "foo"
> _Static_assert(0, "foo");
> ^~~~~~~~~~~~~~
>
> ..., and for C++ we diagnost:
>
> [...]:4:1: error: static assertion failed: foo
> static_assert(0, "foo");
> ^~~~~~~~~~~~~
>
> ("foo" quoted vs. un-quoted.) Assuming this difference between C and C++
> diagnostics is not intentional, which one should we settle on? I thought
> I'd like the un-quoted version better, but judging by Martin's recent
> wiki change (see below), "foo" is a string constant, so should be quoted
> in diagnostics? If yes, OK to commit to trunk the obvious changes (plus
> any testsuite updates)?
From a diagnostics point-of-view, neither version is quoted:
c/c-parser.c: error_at (assert_loc, "static assertion failed: %E", string);
cp/semantics.c: error ("static assertion failed: %s",
To be "quoted", it would need to use either %q or %<%>. Note that %qs would
produce `foo' not "foo". Nevertheless, we probably want to print 'x' for
character literals and not `'x'' and "string" for string literals and not
`string'. Thus, the wiki should probably be amended to clarify this.
Also, there is a substantial difference between %E and %s when the string
contains control characters such as \n \t \u etc. Clang uses something similar
to %E.
For comparison, we use %s to print
test.c:1:9: note: #pragma message:
string
#pragma message "\nstring"
^
Cheers,
Manuel.
More information about the Gcc
mailing list