This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: "error: static assertion failed: [...]"
- From: Martin Sebor <msebor at gmail dot com>
- To: Thomas Schwinge <thomas at codesourcery dot com>, gcc at gcc dot gnu dot org
- Date: Wed, 13 Jul 2016 20:43:14 -0600
- Subject: Re: "error: static assertion failed: [...]"
- Authentication-results: sourceware.org; auth=none
- References: <20160712223417.88257.78300@sourceware.org> <87shvdekj5.fsf@kepler.schwinge.homeip.net>
On 07/13/2016 07:26 AM, 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)?
I hadn't thought of this case. I don't have a personal preference
but I can provide a few data points to help with the decision (or
maybe muddy the waters).
Neither the C nor the C++ standard specifies whether or not to
include the quotes. Both simply require that
...the implementation shall produce a diagnostic message that
includes the text of the string literal, ...
Of the compilers I tried (Clang, EDG eccp, IBM XLC, Microsoft
Visual C++, and Oracle CC), more include the quotes in both
languages than not. IBM XLC only quotes the C++ text, the
opposite of G++. Visual C++ doesn't quote the C++ text and
doesn't understand the C11 _Static_assert.
From other similar constructs, C and C++ specify that the #error
directive include the preprocessing tokens that follow it (i.e.,
including quotes).
GCC doesn't include the quotes when printing the string argument
in attribute error.
Martin
For reference:
On Tue, 12 Jul 2016 22:34:17 -0000, GCC Wiki <noreply@gcc.gnu.org> wrote:
The "DiagnosticsGuidelines" page has been changed by MartinSebor:
https://gcc.gnu.org/wiki/DiagnosticsGuidelines?action=diff&rev1=7&rev2=8
Comment:
Added a table of contents and a Quoting section.
+ === Quoting ===
+
+ The following elements should be quoted in GCC diagnostics, either using the {{{q}}} modifier in a directive such as {{{%qE}}}, or by enclosing the quoted text in a pair of {{{%<}}} and {{{%>}}} directives:
+
+ * Language keywords.
+ * Tokens.
+ * Boolean, numerical, character, and string constants that appear in the source code.
+ * Identifiers, including function, macro, type, and variable names.
+
+ Other elements such as numbers that do no refer to numeric constants that appear in the source code should not be quoted. For example, in the message:
+ {{{#!highlight c++ numbers=disable
+ argument %d of %qE must be a pointer type
+ }}}
+ since the argument number does not refer to a numerical constant in the source code it should not be quoted.
Grüße
Thomas