Provide diagnostic hints for missing C++ cinttypes string constants.
authorMark Wielaard <mark@klomp.org>
Sat, 23 May 2020 22:44:22 +0000 (00:44 +0200)
committerMark Wielaard <mark@klomp.org>
Wed, 3 Jun 2020 23:22:53 +0000 (01:22 +0200)
commit1dc83b460653c29f96b4659579e2151fae0d1e6e
tree946ec0b018766ecb4f0e8c005c8e4dc3ac81d04a
parent9eea5d2ddf73037e21b59bcd8084ba969ae10174
Provide diagnostic hints for missing C++ cinttypes string constants.

When reporting an error in cp_parser and we notice a string literal
followed by an unknown name check whether there is a known standard
header containing a string macro with the same name, then add a hint
to the error message to include that header.

gcc/c-family/ChangeLog:

* known-headers.cc (get_cp_stdlib_header_for_string_macro_name):
New function.
* known-headers.h (get_cp_stdlib_header_for_string_macro_name):
New function declaration.

gcc/cp/ChangeLog:

* parser.c (cp_lexer_safe_previous_token): New function.
(cp_parser_error_1): Add name_hint if the previous token is
a string literal and next token is a CPP_NAME and we have a
missing header suggestion for the name.

gcc/testsuite/ChangeLog:

* g++.dg/spellcheck-inttypes.C: Add string-literal testcases.
gcc/c-family/known-headers.cc
gcc/c-family/known-headers.h
gcc/cp/parser.c
gcc/testsuite/g++.dg/spellcheck-inttypes.C