aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/parser.cc
diff options
context:
space:
mode:
authorNathaniel Shead <nathanieloshead@gmail.com>2024-08-07 19:20:19 +1000
committerNathaniel Shead <nathanieloshead@gmail.com>2024-09-05 22:00:51 +1000
commitcb76fcf5ebf0817e6f1b7c019071362f7a5f3ae0 (patch)
treeb84dad03bf4a28cbd8d60d60ac3179bac95d04db /gcc/cp/parser.cc
parent7b8da316089bfdf299592a88fdab2f93c444b03a (diff)
downloadgcc-cb76fcf5ebf0817e6f1b7c019071362f7a5f3ae0.zip
gcc-cb76fcf5ebf0817e6f1b7c019071362f7a5f3ae0.tar.gz
gcc-cb76fcf5ebf0817e6f1b7c019071362f7a5f3ae0.tar.bz2
c++: Add missing auto_diagnostic_groups
This patch goes through all .cc files in gcc/cp and adds in any auto_diagnostic_groups that seem to be missing by looking for any 'inform' calls that aren't grouped with their respective error/warning. Now with SARIF output support this seems to be a bit more important. The patch isn't complete; I've tried to also track helper functions used for diagnostics to group them, but some may have been missed. Additionally there are a few functions that are definitely missing groupings but I wasn't able to see an obvious way to add them without potentially grouping together unrelated messages. This list includes: - lazy_load_{binding,pendings} "during load of {binding,pendings} for" - cp_finish_decomp "in initialization of structured binding variable" - require_deduced_type "using __builtin_source_location" - convert_nontype_argument "in template argument for type %qT" - coerce_template_params "so any instantiation with a non-empty parameter pack" - tsubst_default_argument "when instantiating default argument" - invalid_nontype_parm_type_p "invalid template non-type parameter" gcc/cp/ChangeLog: * class.cc (add_method): Add missing auto_diagnostic_group. (handle_using_decl): Likewise. (maybe_warn_about_overly_private_class): Likewise. (check_field_decl): Likewise. (check_field_decls): Likewise. (resolve_address_of_overloaded_function): Likewise. (note_name_declared_in_class): Likewise. * constraint.cc (associate_classtype_constraints): Likewise. (diagnose_trait_expr): Clean up whitespace. * coroutines.cc (find_coro_traits_template_decl): Add missing auto_diagnostic_group. (coro_promise_type_found_p): Likewise. (coro_diagnose_throwing_fn): Likewise. * cvt.cc (build_expr_type_conversion): Likewise. * decl.cc (validate_constexpr_redeclaration): Likewise. (duplicate_function_template_decls): Likewise. (duplicate_decls): Likewise. (lookup_label_1): Likewise. (check_previous_goto_1): Likewise. (check_goto_1): Likewise. (make_typename_type): Likewise. (make_unbound_class_template): Likewise. (check_tag_decl): Likewise. (start_decl): Likewise. (maybe_commonize_var): Likewise. (check_for_uninitialized_const_var): Likewise. (reshape_init_class): Likewise. (check_initializer): Likewise. (cp_finish_decl): Likewise. (find_decomp_class_base): Likewise. (cp_finish_decomp): Likewise. (expand_static_init): Likewise. (grokfndecl): Likewise. (grokdeclarator): Likewise. (check_elaborated_type_specifier): Likewise. (lookup_and_check_tag): Likewise. (xref_tag): Likewise. (cxx_simulate_enum_decl): Likewise. (finish_function): Likewise. * decl2.cc (check_classfn): Likewise. (record_mangling): Likewise. (mark_used): Likewise. * error.cc (qualified_name_lookup_error): Likewise. * except.cc (build_throw): Likewise. * init.cc (get_nsdmi): Likewise. (diagnose_uninitialized_cst_or_ref_member_1): Likewise. (warn_placement_new_too_small): Likewise. (build_new_1): Likewise. (build_vec_delete_1): Likewise. (build_delete): Likewise. * lambda.cc (add_capture): Likewise. (add_default_capture): Likewise. * lex.cc (unqualified_fn_lookup_error): Likewise. * method.cc (synthesize_method): Likewise. (defaulted_late_check): Likewise. * module.cc (trees_in::is_matching_decl): Likewise. (trees_in::read_enum_def): Likewise. (module_state::check_not_purview): Likewise. (module_state::deferred_macro): Likewise. (module_state::read_config): Likewise. (module_state::check_read): Likewise. (declare_module): Likewise. (init_modules): Likewise. * name-lookup.cc (diagnose_name_conflict): Likewise. (lookup_using_decl): Likewise. (set_decl_namespace): Likewise. (finish_using_directive): Likewise. (push_namespace): Likewise. (add_imported_namespace): Likewise. * parser.cc (cp_parser_check_for_definition_in_return_type): Likewise. (cp_parser_userdef_numeric_literal): Likewise. (cp_parser_nested_name_specifier_opt): Likewise. (cp_parser_new_expression): Likewise. (cp_parser_binary_expression): Likewise. (cp_parser_lambda_introducer): Likewise. (cp_parser_module_declaration): Likewise. (cp_parser_import_declaration): Likewise, removing gotos to support this. (cp_parser_declaration): Add missing auto_diagnostic_group. (cp_parser_decl_specifier_seq): Likewise. (cp_parser_template_id): Likewise. (cp_parser_template_name): Likewise. (cp_parser_explicit_specialization): Likewise. (cp_parser_placeholder_type_specifier): Likewise. (cp_parser_elaborated_type_specifier): Likewise. (cp_parser_enum_specifier): Likewise. (cp_parser_asm_definition): Likewise. (cp_parser_init_declarator): Likewise. (cp_parser_direct_declarator): Likewise. (cp_parser_class_head): Likewise. (cp_parser_member_declaration): Likewise. (cp_parser_lookup_name): Likewise. (cp_parser_explicit_template_declaration): Likewise. (cp_parser_check_class_key): Likewise. * pt.cc (maybe_process_partial_specialization): Likewise. (determine_specialization): Likewise. (check_for_bare_parameter_packs): Likewise. (check_template_shadow): Likewise. (process_partial_specialization): Likewise. (push_template_decl): Likewise. (redeclare_class_template): Likewise. (convert_nontype_argument_function): Likewise. (check_valid_ptrmem_cst_expr): Likewise. (convert_nontype_argument): Likewise. (convert_template_argument): Likewise. (coerce_template_parms): Likewise. (tsubst_qualified_id): Likewise. (tsubst_expr): Likewise. (most_specialized_partial_spec): Likewise. (do_class_deduction): Likewise. (do_auto_deduction): Likewise. * search.cc (lookup_member): Likewise. * semantics.cc (finish_non_static_data_member): Likewise. (process_outer_var_ref): Likewise. (finish_id_expression_1): Likewise. (finish_offsetof): Likewise. (omp_reduction_lookup): Likewise. (finish_omp_clauses): Likewise. * tree.cc (check_abi_tag_redeclaration): Likewise. (check_abi_tag_args): Likewise. * typeck.cc (invalid_nonstatic_memfn_p): Likewise. (complain_about_unrecognized_member): Likewise. (finish_class_member_access_expr): Likewise. (error_args_num): Likewise. (warn_for_null_address): Likewise. (cp_build_binary_op): Likewise. (build_x_unary_op): Likewise. (cp_build_unary_op): Likewise. (build_static_cast): Likewise. (cp_build_modify_expr): Likewise. (get_delta_difference): Likewise. (convert_for_assignment): Widen scope of auto_diagnostic_group. (check_return_expr): Add missing auto_diagnostic_group. * typeck2.cc (cxx_incomplete_type_diagnostic): Likewise. Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com> Reviewed-by: Marek Polacek <polacek@redhat.com>
Diffstat (limited to 'gcc/cp/parser.cc')
-rw-r--r--gcc/cp/parser.cc107
1 files changed, 73 insertions, 34 deletions
diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index 64122d9..5654bc0 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -3504,6 +3504,7 @@ cp_parser_check_for_definition_in_return_type (cp_declarator *declarator,
if (declarator
&& declarator->kind == cdk_function)
{
+ auto_diagnostic_group d;
error_at (type_location,
"new types may not be defined in a return type");
inform (type_location,
@@ -5086,24 +5087,27 @@ cp_parser_userdef_numeric_literal (cp_parser *parser)
}
}
- bool complained
- = emit_diagnostic (kind, input_location, opt,
- "unable to find numeric literal operator %qD", name);
-
- if (!complained)
- /* Don't inform either. */;
- else if (i14)
- {
- inform (token->location, "add %<using namespace std::complex_literals%> "
- "(from %<<complex>%>) to enable the C++14 user-defined literal "
- "suffixes");
- if (ext)
- inform (token->location, "or use %<j%> instead of %<i%> for the "
- "GNU built-in suffix");
- }
- else if (!ext)
- inform (token->location, "use %<-fext-numeric-literals%> "
- "to enable more built-in suffixes");
+ {
+ auto_diagnostic_group d;
+ bool complained
+ = emit_diagnostic (kind, input_location, opt,
+ "unable to find numeric literal operator %qD", name);
+
+ if (!complained)
+ /* Don't inform either. */;
+ else if (i14)
+ {
+ inform (token->location, "add %<using namespace std::complex_literals%> "
+ "(from %<<complex>%>) to enable the C++14 user-defined literal "
+ "suffixes");
+ if (ext)
+ inform (token->location, "or use %<j%> instead of %<i%> for the "
+ "GNU built-in suffix");
+ }
+ else if (!ext)
+ inform (token->location, "use %<-fext-numeric-literals%> "
+ "to enable more built-in suffixes");
+ }
if (kind == DK_ERROR)
value = error_mark_node;
@@ -7159,6 +7163,7 @@ cp_parser_nested_name_specifier_opt (cp_parser *parser,
if (TREE_CODE (tid) == TEMPLATE_ID_EXPR
&& TREE_CODE (TREE_OPERAND (tid, 0)) != IDENTIFIER_NODE)
{
+ auto_diagnostic_group d;
tree tmpl = NULL_TREE;
if (is_overloaded_fn (tid))
{
@@ -9641,10 +9646,13 @@ cp_parser_new_expression (cp_parser* parser)
message for this case. */
if (cp_lexer_next_token_is (parser->lexer, CPP_OPEN_SQUARE))
{
- error_at (token->location,
- "array bound forbidden after parenthesized type-id");
- inform (token->location,
- "try removing the parentheses around the type-id");
+ {
+ auto_diagnostic_group d;
+ error_at (token->location,
+ "array bound forbidden after parenthesized type-id");
+ inform (token->location,
+ "try removing the parentheses around the type-id");
+ }
cp_parser_direct_new_declarator (parser);
}
}
@@ -10450,6 +10458,7 @@ cp_parser_binary_expression (cp_parser* parser, bool cast_p,
&& token->type == CPP_RSHIFT
&& !parser->greater_than_is_operator_p)
{
+ auto_diagnostic_group d;
if (warning_at (token->location, OPT_Wc__11_compat,
"%<>>%> operator is treated"
" as two right angle brackets in C++11"))
@@ -11724,6 +11733,7 @@ cp_parser_lambda_introducer (cp_parser* parser, tree lambda_expr)
else if (!VAR_P (capture_init_expr)
&& TREE_CODE (capture_init_expr) != PARM_DECL)
{
+ auto_diagnostic_group d;
error_at (capture_token->location,
"capture of non-variable %qE",
capture_init_expr);
@@ -11735,6 +11745,7 @@ cp_parser_lambda_introducer (cp_parser* parser, tree lambda_expr)
if (VAR_P (capture_init_expr)
&& decl_storage_duration (capture_init_expr) != dk_auto)
{
+ auto_diagnostic_group d;
if (pedwarn (capture_token->location, 0, "capture of variable "
"%qD with non-automatic storage duration",
capture_init_expr))
@@ -15238,6 +15249,7 @@ cp_parser_module_declaration (cp_parser *parser, module_parse mp_state,
}
else if (scope != global_namespace)
{
+ auto_diagnostic_group d;
error_at (token->location, "module-declaration must be at global scope");
inform (DECL_SOURCE_LOCATION (scope), "scope opened here");
goto skip_eol;
@@ -15315,19 +15327,22 @@ cp_parser_import_declaration (cp_parser *parser, module_parse mp_state,
if (mp_state == MP_PURVIEW || mp_state == MP_PRIVATE)
{
+ auto_diagnostic_group d;
error_at (token->location, "post-module-declaration"
" imports must be contiguous");
- note_lexer:
inform (token->location, "perhaps insert a line break after"
" %<import%>, or other disambiguation, to prevent this"
" being considered a module control-line");
- skip_eol:
cp_parser_skip_to_pragma_eol (parser, token);
}
else if (current_scope () != global_namespace)
{
+ auto_diagnostic_group d;
error_at (token->location, "import-declaration must be at global scope");
- goto note_lexer;
+ inform (token->location, "perhaps insert a line break after"
+ " %<import%>, or other disambiguation, to prevent this"
+ " being considered a module control-line");
+ cp_parser_skip_to_pragma_eol (parser, token);
}
else
{
@@ -15355,7 +15370,10 @@ cp_parser_import_declaration (cp_parser *parser, module_parse mp_state,
tree attrs = cp_parser_attributes_opt (parser);
if (!mod || !cp_parser_require (parser, CPP_SEMICOLON, RT_SEMICOLON))
- goto skip_eol;
+ {
+ cp_parser_skip_to_pragma_eol (parser, token);
+ return;
+ }
cp_parser_require_pragma_eol (parser, token);
if (mp_state == MP_PURVIEW_IMPORTS || mp_state == MP_PRIVATE_IMPORTS)
@@ -15648,6 +15666,7 @@ cp_parser_declaration (cp_parser* parser, tree prefix_attrs)
if (!c_dialect_objc ())
{
location_t where = get_finish (t2->location);
+ auto_diagnostic_group d;
warning_at (token1->location, OPT_Wattributes, "attributes are"
" not permitted in this position");
where = linemap_position_for_loc_and_offset (line_table,
@@ -16899,6 +16918,7 @@ cp_parser_decl_specifier_seq (cp_parser* parser,
if (decl_specs->std_attributes)
{
+ auto_diagnostic_group d;
error_at (decl_specs->locations[ds_std_attribute],
"standard attributes in middle of decl-specifiers");
inform (decl_specs->locations[ds_std_attribute],
@@ -19148,6 +19168,7 @@ cp_parser_template_id (cp_parser *parser,
}
/* Otherwise, emit an error about the invalid digraph, but continue
parsing because we got our argument list. */
+ auto_diagnostic_group d;
if (permerror (next_token->location,
"%<<::%> cannot begin a template-argument list"))
{
@@ -19187,6 +19208,7 @@ cp_parser_template_id (cp_parser *parser,
/* C++20 says that "function-name < a;" is now ill-formed. */
if (cp_parser_error_occurred (parser))
{
+ auto_diagnostic_group d;
error_at (token->location, "invalid template-argument-list");
inform (token->location, "function name as the left hand "
"operand of %<<%> is ill-formed in C++20; wrap the "
@@ -19432,10 +19454,13 @@ cp_parser_template_name (cp_parser* parser,
cp_token_position start = 0;
/* Explain what went wrong. */
- error_at (token->location, "non-template %qD used as template",
- identifier);
- inform (token->location, "use %<%T::template %D%> to indicate that it is a template",
- parser->scope, identifier);
+ {
+ auto_diagnostic_group d;
+ error_at (token->location, "non-template %qD used as template",
+ identifier);
+ inform (token->location, "use %<%T::template %D%> to indicate "
+ "that it is a template", parser->scope, identifier);
+ }
/* If parsing tentatively, find the location of the "<" token. */
if (cp_parser_simulate_error (parser))
start = cp_lexer_token_position (parser->lexer, true);
@@ -20103,6 +20128,7 @@ cp_parser_explicit_specialization (cp_parser* parser)
bool need_lang_pop = current_lang_name == lang_name_c;
if (need_lang_pop)
{
+ auto_diagnostic_group d;
error_at (token->location, "template specialization with C linkage");
maybe_show_extern_c_location ();
@@ -20935,6 +20961,7 @@ cp_parser_placeholder_type_specifier (cp_parser *parser, location_t loc,
{
if (!tentative)
{
+ auto_diagnostic_group d;
error_at (loc, "%qE does not constrain a type", DECL_NAME (con));
inform (DECL_SOURCE_LOCATION (con), "concept defined here");
}
@@ -21548,6 +21575,7 @@ cp_parser_elaborated_type_specifier (cp_parser* parser,
"attributes ignored on template instantiation");
else if (is_friend && cxx11_attribute_p (attributes))
{
+ auto_diagnostic_group d;
if (warning (OPT_Wattributes, "attribute ignored"))
inform (input_location, "an attribute that appertains to a friend "
"declaration that is not a definition is ignored");
@@ -21900,6 +21928,7 @@ cp_parser_enum_specifier (cp_parser* parser)
}
else
{
+ auto_diagnostic_group d;
error_at (type_start_token->location,
"multiple definition of %q#T", type);
inform (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (type)),
@@ -22947,6 +22976,7 @@ cp_parser_asm_definition (cp_parser* parser)
case RID_VOLATILE:
if (volatile_loc)
{
+ auto_diagnostic_group d;
error_at (loc, "duplicate %<asm%> qualifier %qT",
token->u.value);
inform (volatile_loc, "first seen here");
@@ -22964,6 +22994,7 @@ cp_parser_asm_definition (cp_parser* parser)
case RID_INLINE:
if (inline_loc)
{
+ auto_diagnostic_group d;
error_at (loc, "duplicate %<asm%> qualifier %qT",
token->u.value);
inform (inline_loc, "first seen here");
@@ -22978,6 +23009,7 @@ cp_parser_asm_definition (cp_parser* parser)
case RID_GOTO:
if (goto_loc)
{
+ auto_diagnostic_group d;
error_at (loc, "duplicate %<asm%> qualifier %qT",
token->u.value);
inform (goto_loc, "first seen here");
@@ -23791,12 +23823,13 @@ cp_parser_init_declarator (cp_parser* parser,
attributes -- but ignores them. Made a permerror in GCC 8. */
if (cp_parser_allow_gnu_extensions_p (parser)
&& initialization_kind == CPP_OPEN_PAREN
- && cp_parser_attributes_opt (parser)
- && permerror (input_location,
- "attributes after parenthesized initializer ignored"))
+ && cp_parser_attributes_opt (parser))
{
static bool hint;
- if (flag_permissive && !hint)
+ auto_diagnostic_group d;
+ if (permerror (input_location,
+ "attributes after parenthesized initializer ignored")
+ && flag_permissive && !hint)
{
hint = true;
inform (input_location,
@@ -24496,6 +24529,7 @@ cp_parser_direct_declarator (cp_parser* parser,
else if (qualifying_scope
&& CLASSTYPE_USE_TEMPLATE (name_type))
{
+ auto_diagnostic_group d;
error_at (declarator_id_start_token->location,
"invalid use of constructor as a template");
inform (declarator_id_start_token->location,
@@ -27890,6 +27924,7 @@ cp_parser_class_head (cp_parser* parser,
if (type != error_mark_node
&& (COMPLETE_TYPE_P (type) || TYPE_BEING_DEFINED (type)))
{
+ auto_diagnostic_group d;
error_at (type_start_token->location, "redefinition of %q#T",
type);
inform (location_of (type), "previous definition of %q#T",
@@ -28344,6 +28379,7 @@ cp_parser_member_declaration (cp_parser* parser)
&& cxx11_attribute_p (decl_specifiers.attributes))
{
decl_specifiers.attributes = NULL_TREE;
+ auto_diagnostic_group d;
if (warning_at (decl_spec_token_start->location,
OPT_Wattributes, "attribute ignored"))
inform (decl_spec_token_start->location, "an attribute "
@@ -32448,6 +32484,7 @@ cp_parser_lookup_name (cp_parser *parser, tree name,
cp_parser_error, so we incorporate its actions directly. */
if (!cp_parser_simulate_error (parser))
{
+ auto_diagnostic_group d;
error_at (name_location, "reference to %qD is ambiguous",
name);
print_candidates (decl);
@@ -33259,6 +33296,7 @@ cp_parser_explicit_template_declaration (cp_parser* parser, bool member_p)
A template ... shall not have C linkage. */
if (current_lang_name == lang_name_c)
{
+ auto_diagnostic_group d;
error_at (location, "template with C linkage");
maybe_show_extern_c_location ();
/* Give it C++ linkage to avoid confusing other parts of the
@@ -35235,6 +35273,7 @@ cp_parser_check_class_key (cp_parser *parser, location_t key_loc,
bool seen_as_union = TREE_CODE (type) == UNION_TYPE;
if (seen_as_union != (class_key == union_type))
{
+ auto_diagnostic_group d;
if (permerror (input_location, "%qs tag used in naming %q#T",
class_key == union_type ? "union"
: class_key == record_type ? "struct" : "class",