This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [C PATCH] PR43651: add warning for duplicate qualifier


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]