This is the mail archive of the
mailing list for the GCC project.
Re: "error: static assertion failed: [...]"
- From: Martin Sebor <msebor at gmail dot com>
- To: Manuel López-Ibáñez <lopezibanez at gmail dot com>, Thomas Schwinge <thomas at codesourcery dot com>, gcc at gcc dot gnu dot org
- Date: Sat, 16 Jul 2016 17:22:28 -0600
- Subject: Re: "error: static assertion failed: [...]"
- Authentication-results: sourceware.org; auth=none
- References: <firstname.lastname@example.org> <email@example.com> <5786FD08.firstname.lastname@example.org>
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
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.
I agree that the two sets of quotes in '"string"' don't look quite
right, and that letting embedded control sequences affect the compiler
output probably isn't a good idea. Which, AFAICT, leaves a plain %E
as the only option.
The nice thing about %qE (or %<%E%>) vs plain %E is that the former
highlight the text of the string (i.e., make it bold). That makes
the reason for the error stand out. It would be nice if there were
a way to do that without adding the extra pair of quotes or giving
up on the control character transformation.
For comparison, we use %s to print
test.c:1:9: note: #pragma message:
#pragma message "\nstring"
That seems potentially unsafe and might be worth changing to match