This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: "error: static assertion failed: [...]" (was: [GCC Wiki] Update of "DiagnosticsGuidelines" by MartinSebor)
- From: Manuel López-Ibáñez <lopezibanez at gmail dot com>
- To: Thomas Schwinge <thomas at codesourcery dot com>, gcc at gcc dot gnu dot org
- Cc: Martin Sebor <msebor at gmail dot com>
- Date: Thu, 14 Jul 2016 03:46:32 +0100
- Subject: Re: "error: static assertion failed: [...]" (was: [GCC Wiki] Update of "DiagnosticsGuidelines" by MartinSebor)
- Authentication-results: sourceware.org; auth=none
- References: <20160712223417.88257.78300@sourceware.org> <87shvdekj5.fsf@kepler.schwinge.homeip.net>
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.