aboutsummaryrefslogtreecommitdiff
path: root/gcc/c-family
diff options
context:
space:
mode:
authorMark Wielaard <mark@klomp.org>2020-05-24 00:44:22 +0200
committerMark Wielaard <mark@klomp.org>2020-06-04 01:22:53 +0200
commit1dc83b460653c29f96b4659579e2151fae0d1e6e (patch)
tree946ec0b018766ecb4f0e8c005c8e4dc3ac81d04a /gcc/c-family
parent9eea5d2ddf73037e21b59bcd8084ba969ae10174 (diff)
downloadgcc-1dc83b460653c29f96b4659579e2151fae0d1e6e.zip
gcc-1dc83b460653c29f96b4659579e2151fae0d1e6e.tar.gz
gcc-1dc83b460653c29f96b4659579e2151fae0d1e6e.tar.bz2
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.
Diffstat (limited to 'gcc/c-family')
-rw-r--r--gcc/c-family/known-headers.cc8
-rw-r--r--gcc/c-family/known-headers.h1
2 files changed, 9 insertions, 0 deletions
diff --git a/gcc/c-family/known-headers.cc b/gcc/c-family/known-headers.cc
index c07cfd1..977230a 100644
--- a/gcc/c-family/known-headers.cc
+++ b/gcc/c-family/known-headers.cc
@@ -268,6 +268,14 @@ get_c_stdlib_header_for_string_macro_name (const char *name)
return get_string_macro_hint (name, STDLIB_C);
}
+/* Given non-NULL NAME, return the header name defining a string macro
+ within the C++ standard library (with '<' and '>'), or NULL. */
+const char *
+get_cp_stdlib_header_for_string_macro_name (const char *name)
+{
+ return get_string_macro_hint (name, STDLIB_CPLUSPLUS);
+}
+
/* Implementation of class suggest_missing_header. */
/* suggest_missing_header's ctor. */
diff --git a/gcc/c-family/known-headers.h b/gcc/c-family/known-headers.h
index a69bbbf..f0c89dc 100644
--- a/gcc/c-family/known-headers.h
+++ b/gcc/c-family/known-headers.h
@@ -24,6 +24,7 @@ extern const char *get_c_stdlib_header_for_name (const char *name);
extern const char *get_cp_stdlib_header_for_name (const char *name);
extern const char *get_c_stdlib_header_for_string_macro_name (const char *n);
+extern const char *get_cp_stdlib_header_for_string_macro_name (const char *n);
/* Subclass of deferred_diagnostic for suggesting to the user
that they have missed a #include. */