]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c-family: Have -Wformat-diag accept "decl-specifier" [PR103758]
authorMarek Polacek <polacek@redhat.com>
Fri, 17 Dec 2021 19:34:12 +0000 (14:34 -0500)
committerMarek Polacek <polacek@redhat.com>
Mon, 3 Jan 2022 20:53:59 +0000 (15:53 -0500)
I'm tired of seeing

cp/parser.c:15923:55: warning: misspelled term 'decl' in format; use 'declaration' instead [-Wformat-diag]
cp/parser.c:15925:57: warning: misspelled term 'decl' in format; use 'declaration' instead [-Wformat-diag]

every time I compile cp/parser.c, which happens...a lot.  I'd like my
compilation to be free of warnings, otherwise I'm going to miss some
important ones.

"decl-specifiers" is a C++ grammar term; it is not actual code, so
should not be wrapped with %< %>.  I hope we can accept it as an exception
in check_tokens.

It was surrounded by %< %> in cp_parser_decl_specifier_seq, so fix that.

In passing, fix a misspelling in missspellings.

PR c++/103758

gcc/c-family/ChangeLog:

* c-format.c (check_tokens): Accept "decl-specifier*".

gcc/cp/ChangeLog:

* parser.c (cp_parser_decl_specifier_seq): Replace %<decl-specifier%>
with %qD.

gcc/testsuite/ChangeLog:

* g++.dg/cpp0x/constexpr-condition.C: Adjust dg-error.

gcc/c-family/c-format.c
gcc/cp/parser.c
gcc/testsuite/g++.dg/cpp0x/constexpr-condition.C

index 7d3b3117ee262a50d6e2ea2b8ba4fb47853a3fc7..afa77810a5cead201c7b624d39e4e6ca599d1a15 100644 (file)
@@ -3194,7 +3194,7 @@ check_tokens (const token_t *tokens, unsigned ntoks,
                           wlen, format_chars);
   else
     {
-      /* Diagnose some common missspellings.  */
+      /* Diagnose some common misspellings.  */
       for (unsigned i = 0; i != sizeof badwords / sizeof *badwords; ++i)
        {
          unsigned badwlen = strspn (badwords[i].name, " -");
@@ -3215,6 +3215,12 @@ check_tokens (const token_t *tokens, unsigned ntoks,
                  plural = "s";
                }
 
+             /* As an exception, don't warn about "decl-specifier*" since
+                it's a C++ grammar production.  */
+             if (badwords[i].name[0] == 'd'
+                 && startswith (format_chars, "decl-specifier"))
+               continue;
+
              format_warning_substr (format_string_loc, format_string_cst,
                                     fmtchrpos, fmtchrpos + badwords[i].len,
                                     opt,
index 4475f79291665901dab6404c85a2d907c3e0e59a..6b91a0ce4912f37dc1786278f029488287ba07fa 100644 (file)
@@ -15821,7 +15821,7 @@ cp_parser_decl_specifier_seq (cp_parser* parser,
       if (found_decl_spec
          && (flags & CP_PARSER_FLAGS_ONLY_TYPE_OR_CONSTEXPR)
          && token->keyword != RID_CONSTEXPR)
-       error ("%<decl-specifier%> invalid in condition");
+       error ("%qD invalid in condition", ridpointers[token->keyword]);
 
       if (found_decl_spec
          && (flags & CP_PARSER_FLAGS_ONLY_MUTABLE_OR_CONSTEXPR)
index 733d494c4d71d2ff58eb66cfc8f14d2040ac870a..e81acba68ae1bd612bfa40d225ff25f6a857eef7 100644 (file)
@@ -5,5 +5,5 @@ constexpr int something() { return 3; }
 
 int main() {
   if (constexpr long v = something()) {}
-  if (static long v = something()) { } // { dg-error "'decl-specifier' invalid" }
+  if (static long v = something()) { } // { dg-error "'static' invalid" }
 }