[Bug c/43651] add warning for duplicate qualifier

2016-05-11 Thread miyuki at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=43651

Mikhail Maltsev  changed:

   What|Removed |Added

 Status|UNCONFIRMED |RESOLVED
 Resolution|--- |FIXED

--- Comment #9 from Mikhail Maltsev  ---
Fixed for GCC 7.

[Bug c/43651] add warning for duplicate qualifier

2016-05-11 Thread miyuki at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=43651

--- Comment #8 from Mikhail Maltsev  ---
Author: miyuki
Date: Wed May 11 20:23:37 2016
New Revision: 236142

URL: https://gcc.gnu.org/viewcvs?rev=236142=gcc=rev
Log:
PR43651: add warning for duplicate qualifier

gcc/c/

PR c/43651
* c-decl.c (declspecs_add_qual): Warn when -Wduplicate-decl-specifier
is enabled.
* c-errors.c (pedwarn_c90): Return true if warned.
* c-tree.h (pedwarn_c90): Change return type to bool.
(enum c_declspec_word): Add new enumerator cdw_atomic.

gcc/

PR c/43651
* doc/invoke.texi (Wduplicate-decl-specifier): Document new option.

gcc/testsuite/

PR c/43651
* gcc.dg/Wduplicate-decl-specifier-c11.c: New test.
* gcc.dg/Wduplicate-decl-specifier.c: Likewise.

gcc/c-family/

PR c/43651
* c.opt (Wduplicate-decl-specifier): New option.

Added:
trunk/gcc/testsuite/gcc.dg/Wduplicate-decl-specifier-c11.c
trunk/gcc/testsuite/gcc.dg/Wduplicate-decl-specifier.c
Modified:
trunk/gcc/ChangeLog
trunk/gcc/c-family/ChangeLog
trunk/gcc/c-family/c.opt
trunk/gcc/c/ChangeLog
trunk/gcc/c/c-decl.c
trunk/gcc/c/c-errors.c
trunk/gcc/c/c-tree.h
trunk/gcc/doc/invoke.texi
trunk/gcc/testsuite/ChangeLog

[Bug c/43651] add warning for duplicate qualifier

2015-09-23 Thread miyuki at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=43651

Mikhail Maltsev  changed:

   What|Removed |Added

 CC||miyuki at gcc dot gnu.org

--- Comment #6 from Mikhail Maltsev  ---
Clang also emits a warning:

$ cat test.c
int foo(const char const *data);

$ /opt/clang-3.6.2/bin/clang -S -std=c89 test.c
test.c:1:20: warning: duplicate 'const' declaration specifier
[-Wduplicate-decl-specifier]
int foo(const char const *data);
   ^~
1 warning generated.
$ /opt/clang-3.6.2/bin/clang -S -std=c99 test.c
test.c:1:20: warning: duplicate 'const' declaration specifier
[-Wduplicate-decl-specifier]
int foo(const char const *data);
   ^
1 warning generated.
$ /opt/clang-3.6.2/bin/clang -xc++ -S -std=c++11 test.c
test.c:1:20: warning: duplicate 'const' declaration specifier
[-Wduplicate-decl-specifier]
int foo(const char const *data);
   ^~
1 warning generated.

"-pedantic-errors" turns this warning into an error in C++ and C89 (but not
C99).

Recently I came across such problem in the code base, which I work with. In
that case it was clearly a mistake, because the author meant 'const char *const
data', so it would be nice if GCC could warn about this.


[Bug c/43651] add warning for duplicate qualifier

2015-09-23 Thread manu at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=43651

--- Comment #7 from Manuel López-Ibáñez  ---
> Recently I came across such problem in the code base, which I work with. In
> that case it was clearly a mistake, because the author meant 'const char
> *const data', so it would be nice if GCC could warn about this.

I think that a patch that warns for 

const Type const x;

but not for:

typedef Type const X;
const X x;

and neither for

#define TYPE Type const
const TYPE;

would be accepted. But someone has to write it.

[Bug c/43651] add warning for duplicate qualifier

2010-12-02 Thread jsm28 at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43651

Joseph S. Myers jsm28 at gcc dot gnu.org changed:

   What|Removed |Added

 CC||fredrik.hederstie...@securi
   ||tas-direct.com

--- Comment #5 from Joseph S. Myers jsm28 at gcc dot gnu.org 2010-12-02 
16:57:02 UTC ---
*** Bug 46765 has been marked as a duplicate of this bug. ***


[Bug c/43651] add warning for duplicate qualifier

2010-04-06 Thread joseph at codesourcery dot com


--- Comment #1 from joseph at codesourcery dot com  2010-04-06 13:07 ---
Subject: Re:   New: add warning for duplicate qualifier

Since C99 allows duplicate qualifiers, this warning is deliberately 
conditional on pedantic  !flag_isoc99.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43651



[Bug c/43651] add warning for duplicate qualifier

2010-04-06 Thread manu at gcc dot gnu dot org


--- Comment #2 from manu at gcc dot gnu dot org  2010-04-06 13:33 ---
What is the rationale for being conditional on pedantic? Is this forbidden by
!c99 and we accept it as an extension?

I understand that it should not be an error in c99 but what to warn is our
decision even if the standard allows it. And a duplicate qualifier (as in the
example) may indicate a mistake. I would rather have it as a pedwarn for
!flag_isoc99 and a normal warning otherwise (perhaps controlled by an option or
by -Wextra). As it is now, it is impossible to get this warning if one is using
c99.


-- 

manu at gcc dot gnu dot org changed:

   What|Removed |Added

 CC||manu at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43651



[Bug c/43651] add warning for duplicate qualifier

2010-04-06 Thread joseph at codesourcery dot com


--- Comment #3 from joseph at codesourcery dot com  2010-04-06 14:14 ---
Subject: Re:  add warning for duplicate qualifier

It is generally presumed that if a new feature is deliberately added in a 
new language version, as with duplicate qualifiers in C99, then it is 
useful for it to be allowed with previous versions and not diagnosed by 
default but only with -pedantic.  The possibility of generally being able 
to warn for C90/C99 compatibility issues whichever mode the compiler is in 
(-Wc90-c99-compat, say) is a separate issue.

I think the reason duplicate qualifiers are allowed in C99 is to allow you 
to use volatile with a typedef name without knowing whether that typedef 
already includes volatile, for example.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43651



[Bug c/43651] add warning for duplicate qualifier

2010-04-06 Thread manu at gcc dot gnu dot org


--- Comment #4 from manu at gcc dot gnu dot org  2010-04-06 14:25 ---
(In reply to comment #3)
 It is generally presumed that if a new feature is deliberately added in a 
 new language version, as with duplicate qualifiers in C99, then it is 
 useful for it to be allowed with previous versions and not diagnosed by 
 default but only with -pedantic. 

OK. I am happy with this answer for the pedantic part. So this is a GCC
extension for C90, hence, pedwarn if !C99 (warned by pedantic, error with
-pedantic-errors). 

 I think the reason duplicate qualifiers are allowed in C99 is to allow you 
 to use volatile with a typedef name without knowing whether that typedef 
 already includes volatile, for example.

I think we are talking about different things. I only want to warn, not
disallow its use. I don't want it to be a pedwarn just a simple warning (which
may be disabled by default). And it only needs to apply to the precise syntax
when the duplicate appears in the same declaration, which is the precise case
covered by the example above, not in qualifiers derived from other declarations
(your typedef example). I think this is the behaviour of icc.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43651