This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [C PATCH] PR43651: add warning for duplicate qualifier
- From: Martin Sebor <msebor at gmail dot com>
- To: Mikhail Maltsev <maltsevm at gmail dot com>, gcc-patches <gcc-patches at gnu dot org>, Joseph Myers <joseph at codesourcery dot com>, Marek Polacek <polacek at redhat dot com>, David Malcolm <dmalcolm at redhat dot com>
- Date: Fri, 8 Apr 2016 11:54:48 -0600
- Subject: Re: [C PATCH] PR43651: add warning for duplicate qualifier
- Authentication-results: sourceware.org; auth=none
- References: <570241F0 dot 3070705 at gmail dot com>
On 04/04/2016 04:29 AM, Mikhail Maltsev wrote:
Hi all!
Currently GCC produces pedantic warning, if variable declaration (or
typedef) has duplicate qualifier, but only when compiling as C89 (not
C99 or C11).
Presumably that's because C89 makes duplicating a type qualifier
a constraint violation while C99 and C11 allow them.
The attached patch adds a new warning option to enable the same warning
in C99 and C11.
It also checks whether qualifiers come from macro
expansion, e.g.:
#define CT2 const int
const CT2 x1;
CT2 const x2;
and does not warn in this case, but warns for, e.g.
void foo(const int const *x) { }
(because this probably meant to be "const int *const x")
The name for new option "-Wduplicate-decl-specifier" and wording was
chosen to match the same option in Clang.
My version of Clang also warns in C++ mode but if I'm reading
the patch right, GCC would warn only C mode. I would find it
surprising if GCC provided the same option as Clang but didn't
make it available in the same languages. Do you have some
reason for leaving it out that I'm not thinking of?
Also, in C11 mode, Clang issues the warning for duplicated
_Atomic qualifiers but it doesn't look like GCC would with
the patch. Here again, unless there's some reason not to,
I would expect GCC to issue the same warning as Clang for
the same code.
Martin