diff options
author | Mikhail Maltsev <maltsevm@gmail.com> | 2016-05-11 20:23:37 +0000 |
---|---|---|
committer | Mikhail Maltsev <miyuki@gcc.gnu.org> | 2016-05-11 20:23:37 +0000 |
commit | d6e83a8dec2b4fd3a92e87add4fa0485dd87d9f7 (patch) | |
tree | 53be56313df606591b5a5db27a863bed98dc7f1a /gcc/c/c-decl.c | |
parent | 51e67ea376b70fd41542c1540d809a32f10ed9ca (diff) | |
download | gcc-d6e83a8dec2b4fd3a92e87add4fa0485dd87d9f7.zip gcc-d6e83a8dec2b4fd3a92e87add4fa0485dd87d9f7.tar.gz gcc-d6e83a8dec2b4fd3a92e87add4fa0485dd87d9f7.tar.bz2 |
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.
From-SVN: r236142
Diffstat (limited to 'gcc/c/c-decl.c')
-rw-r--r-- | gcc/c/c-decl.c | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c index 6ba0e0e..88424a7 100644 --- a/gcc/c/c-decl.c +++ b/gcc/c/c-decl.c @@ -9515,32 +9515,48 @@ declspecs_add_qual (source_location loc, gcc_assert (TREE_CODE (qual) == IDENTIFIER_NODE && C_IS_RESERVED_WORD (qual)); i = C_RID_CODE (qual); + location_t prev_loc = 0; switch (i) { case RID_CONST: dupe = specs->const_p; specs->const_p = true; + prev_loc = specs->locations[cdw_const]; specs->locations[cdw_const] = loc; break; case RID_VOLATILE: dupe = specs->volatile_p; specs->volatile_p = true; + prev_loc = specs->locations[cdw_volatile]; specs->locations[cdw_volatile] = loc; break; case RID_RESTRICT: dupe = specs->restrict_p; specs->restrict_p = true; + prev_loc = specs->locations[cdw_restrict]; specs->locations[cdw_restrict] = loc; break; case RID_ATOMIC: dupe = specs->atomic_p; specs->atomic_p = true; + prev_loc = specs->locations[cdw_atomic]; + specs->locations[cdw_atomic] = loc; break; default: gcc_unreachable (); } if (dupe) - pedwarn_c90 (loc, OPT_Wpedantic, "duplicate %qE", qual); + { + bool warned = pedwarn_c90 (loc, OPT_Wpedantic, + "duplicate %qE declaration specifier", qual); + if (!warned + && warn_duplicate_decl_specifier + && prev_loc >= RESERVED_LOCATION_COUNT + && !from_macro_expansion_at (prev_loc) + && !from_macro_expansion_at (loc)) + warning_at (loc, OPT_Wduplicate_decl_specifier, + "duplicate %qE declaration specifier", qual); + } return specs; } |