diff -urN gcc-15.1.0-orig/gcc/c/c-decl.cc gcc-15.1.0/gcc/c/c-decl.cc --- gcc-15.1.0-orig/gcc/c/c-decl.cc 2025-04-25 17:18:00 +0900 +++ gcc-15.1.0/gcc/c/c-decl.cc 2026-05-15 01:02:19 +0900 @@ -62,6 +62,7 @@ #include "omp-offload.h" /* For offload_vars. */ #include "c-parser.h" #include "gcc-urlifier.h" +#include "flags.h" #include "tree-pretty-print.h" @@ -3581,7 +3582,7 @@ if (flag_isoc99) { - if (const char *suggestion = hint.suggestion ()) + if (const char *suggestion = hint.suggestion (); flag_diagnostics_add_fixits) { gcc_rich_location richloc (loc); richloc.add_fixit_replace (suggestion); @@ -3594,7 +3595,7 @@ warned = permerror_opt (loc, OPT_Wimplicit_function_declaration, "implicit declaration of function %qE", id); } - else if (const char *suggestion = hint.suggestion ()) + else if (const char *suggestion = hint.suggestion (); flag_diagnostics_add_fixits) { gcc_rich_location richloc (loc); richloc.add_fixit_replace (suggestion); @@ -3972,7 +3973,7 @@ if (current_function_decl == NULL_TREE) { name_hint guessed_id = lookup_name_fuzzy (id, FUZZY_LOOKUP_NAME, loc); - if (const char *suggestion = guessed_id.suggestion ()) + if (const char *suggestion = guessed_id.suggestion (); flag_diagnostics_add_fixits) { gcc_rich_location richloc (loc); richloc.add_fixit_replace (suggestion); @@ -3990,7 +3991,7 @@ if (!objc_diagnose_private_ivar (id)) { name_hint guessed_id = lookup_name_fuzzy (id, FUZZY_LOOKUP_NAME, loc); - if (const char *suggestion = guessed_id.suggestion ()) + if (const char *suggestion = guessed_id.suggestion (); flag_diagnostics_add_fixits) { gcc_rich_location richloc (loc); richloc.add_fixit_replace (suggestion); @@ -14019,7 +14020,7 @@ } const char *hint = find_closest_string (IDENTIFIER_POINTER (name), &candidates); - if (hint) + if (hint && flag_diagnostics_add_fixits) { gcc_rich_location richloc (loc); richloc.add_fixit_replace (hint); diff -urN gcc-15.1.0-orig/gcc/c/c-parser.cc gcc-15.1.0/gcc/c/c-parser.cc --- gcc-15.1.0-orig/gcc/c/c-parser.cc 2025-04-25 17:18:00 +0900 +++ gcc-15.1.0/gcc/c/c-parser.cc 2026-05-15 01:02:14 +0900 @@ -77,6 +77,7 @@ #include "asan.h" #include "c-family/c-ubsan.h" #include "gcc-urlifier.h" +#include "flags.h" /* We need to walk over decls with incomplete struct/union/enum types after parsing the whole translation unit. @@ -2356,7 +2357,7 @@ If the user forgot a "struct" etc, suggest inserting it. Otherwise, attempt to look for misspellings. */ gcc_rich_location richloc (here); - if (tag_exists_p (RECORD_TYPE, name)) + if (tag_exists_p (RECORD_TYPE, name) && flag_diagnostics_add_fixits) { /* This is not C++ with its implicit typedef. */ richloc.add_fixit_insert_before ("struct "); @@ -2365,7 +2366,7 @@ " use % keyword to refer to the type", name); } - else if (tag_exists_p (UNION_TYPE, name)) + else if (tag_exists_p (UNION_TYPE, name) && flag_diagnostics_add_fixits) { richloc.add_fixit_insert_before ("union "); error_at (&richloc, @@ -2373,7 +2374,7 @@ " use % keyword to refer to the type", name); } - else if (tag_exists_p (ENUMERAL_TYPE, name)) + else if (tag_exists_p (ENUMERAL_TYPE, name) && flag_diagnostics_add_fixits) { richloc.add_fixit_insert_before ("enum "); error_at (&richloc, @@ -2386,7 +2387,7 @@ auto_diagnostic_group d; name_hint hint = lookup_name_fuzzy (name, FUZZY_LOOKUP_TYPENAME, here); - if (const char *suggestion = hint.suggestion ()) + if (const char *suggestion = hint.suggestion (); flag_diagnostics_add_fixits) { richloc.add_fixit_replace (suggestion); error_at (&richloc, @@ -3580,7 +3581,7 @@ auto_diagnostic_group d; name_hint hint = lookup_name_fuzzy (value, FUZZY_LOOKUP_TYPENAME, loc); - if (const char *suggestion = hint.suggestion ()) + if (const char *suggestion = hint.suggestion (); flag_diagnostics_add_fixits) { gcc_rich_location richloc (loc); richloc.add_fixit_replace (suggestion); @@ -4294,7 +4295,7 @@ location_t semicolon_loc = c_parser_peek_token (parser)->location; gcc_rich_location richloc (semicolon_loc); - richloc.add_fixit_remove (); + if (flag_diagnostics_add_fixits) richloc.add_fixit_remove (); pedwarn (&richloc, OPT_Wpedantic, "extra semicolon in struct or union specified"); c_parser_consume_token (parser); @@ -5287,7 +5288,7 @@ name_hint hint = lookup_name_fuzzy (token->value, FUZZY_LOOKUP_TYPENAME, token->location); - if (const char *suggestion = hint.suggestion ()) + if (const char *suggestion = hint.suggestion (); flag_diagnostics_add_fixits) { gcc_rich_location richloc (token->location); richloc.add_fixit_replace (suggestion); diff -urN gcc-15.1.0-orig/gcc/c/c-typeck.cc gcc-15.1.0/gcc/c/c-typeck.cc --- gcc-15.1.0-orig/gcc/c/c-typeck.cc 2025-04-25 17:18:00 +0900 +++ gcc-15.1.0/gcc/c/c-typeck.cc 2026-05-15 01:04:54 +0900 @@ -55,6 +55,7 @@ #include "realmpfr.h" #include "tree-pretty-print-markup.h" #include "gcc-urlifier.h" +#include "flags.h" /* Possible cases of implicit conversions. Used to select diagnostic messages and control folding initializers in convert_for_assignment. */ @@ -2907,6 +2908,9 @@ static bool should_suggest_deref_p (tree datum_type) { + if (!flag_diagnostics_add_fixits) + return false; + /* We don't do it for Objective-C, since Objective-C 2.0 dot-syntax allows "." for ptrs; we could be handling a failed attempt to access a property. */ @@ -3096,7 +3100,7 @@ if (!field) { tree guessed_id = lookup_field_fuzzy (type, component); - if (guessed_id) + if (guessed_id && flag_diagnostics_add_fixits) { /* Attempt to provide a fixit replacement hint, if we have a valid range for the component. */ @@ -5325,7 +5329,7 @@ { auto_diagnostic_group d; if (warning_at (location, OPT_Wbool_operation, - "%<~%> on a boolean expression")) + "%<~%> on a boolean expression") && flag_diagnostics_add_fixits) { gcc_rich_location richloc (location); richloc.add_fixit_insert_before (location, "!"); @@ -10174,7 +10178,7 @@ if (implicit == 1) { found_missing_braces = 1; - if (initializer_stack->missing_brace_richloc) + if (initializer_stack->missing_brace_richloc && flag_diagnostics_add_fixits) initializer_stack->missing_brace_richloc->add_fixit_insert_before (loc, "{"); } @@ -10277,7 +10281,7 @@ gcc_assert (!constructor_range_stack); } else - if (initializer_stack->missing_brace_richloc) + if (initializer_stack->missing_brace_richloc && flag_diagnostics_add_fixits) initializer_stack->missing_brace_richloc->add_fixit_insert_before (insert_before, "}"); @@ -10685,7 +10689,7 @@ if (field == NULL_TREE) { tree guessed_id = lookup_field_fuzzy (constructor_type, fieldname); - if (guessed_id) + if (guessed_id && flag_diagnostics_add_fixits) { gcc_rich_location rich_loc (fieldname_loc); rich_loc.add_fixit_misspelled_id (fieldname_loc, guessed_id); diff -urN gcc-15.1.0-orig/gcc/c-family/c-common.cc gcc-15.1.0/gcc/c-family/c-common.cc --- gcc-15.1.0-orig/gcc/c-family/c-common.cc 2025-04-25 17:18:00 +0900 +++ gcc-15.1.0/gcc/c-family/c-common.cc 2026-05-15 01:02:08 +0900 @@ -56,6 +56,7 @@ #include "tree-pretty-print-markup.h" #include "gcc-rich-location.h" #include "gcc-urlifier.h" +#include "flags.h" cpp_reader *parse_in; /* Declared in c-pragma.h. */ @@ -9791,6 +9792,9 @@ enum cpp_ttype token_type, location_t prev_token_loc) { + if (!flag_diagnostics_add_fixits) + return; + gcc_assert (richloc); enum missing_token_insertion_kind mtik @@ -9839,6 +9843,9 @@ maybe_emit_indirection_note (location_t loc, tree expr, tree expected_type) { + if (!flag_diagnostics_add_fixits) + return; + gcc_assert (expr); gcc_assert (expected_type); @@ -10016,6 +10023,9 @@ maybe_add_include_fixit (rich_location *richloc, const char *header, bool override_location) { + if (!flag_diagnostics_add_fixits) + return; + location_t loc = richloc->get_loc (); const char *file = LOCATION_FILE (loc); if (!file) diff -urN gcc-15.1.0-orig/gcc/c-family/c-warn.cc gcc-15.1.0/gcc/c-family/c-warn.cc --- gcc-15.1.0-orig/gcc/c-family/c-warn.cc 2025-04-25 17:18:00 +0900 +++ gcc-15.1.0/gcc/c-family/c-warn.cc 2026-05-15 01:01:55 +0900 @@ -41,6 +41,7 @@ #include "tree-pretty-print.h" #include "langhooks.h" #include "gcc-urlifier.h" +#include "flags.h" /* Print a warning if a constant expression had overflow in folding. Invoke this function on every expression that the language @@ -571,7 +572,7 @@ if (warning_at (location, OPT_Wlogical_not_parentheses, "logical not is only applied to the left hand side of " "comparison") - && EXPR_HAS_LOCATION (lhs)) + && EXPR_HAS_LOCATION (lhs) && flag_diagnostics_add_fixits) { location_t lhs_loc = EXPR_LOCATION (lhs); rich_location richloc (line_table, lhs_loc); @@ -3800,7 +3801,7 @@ "elements in this array; element type is " "%qT, not %qT", elt_type, type1)) { - if (EXPR_HAS_LOCATION (op1)) + if (EXPR_HAS_LOCATION (op1) && flag_diagnostics_add_fixits) { location_t op1_loc = EXPR_LOCATION (op1); gcc_rich_location richloc (op1_loc); @@ -3809,7 +3810,7 @@ inform (&richloc, "add parentheses around %qE to " "silence this warning", op1); } - else + else if (flag_diagnostics_add_fixits) inform (loc, "add parentheses around the second % " "to silence this warning"); if (DECL_P (arr)) diff -urN gcc-15.1.0-orig/gcc/common.opt gcc-15.1.0/gcc/common.opt --- gcc-15.1.0-orig/gcc/common.opt 2025-04-25 17:18:00 +0900 +++ gcc-15.1.0/gcc/common.opt 2026-05-15 01:01:18 +0900 @@ -1522,6 +1522,10 @@ EnumValue Enum(diagnostics_output_format) String(sarif-file) Value(DIAGNOSTICS_OUTPUT_FORMAT_SARIF_FILE) +fdiagnostics-add-fixits +Common Var(flag_diagnostics_add_fixits) +Add fix-it hints to diagnostic messages, where available. + fdiagnostics-parseable-fixits Common Var(flag_diagnostics_parseable_fixits) Print fix-it hints in machine-readable form. diff -urN gcc-15.1.0-orig/gcc/cp/decl.cc gcc-15.1.0/gcc/cp/decl.cc --- gcc-15.1.0-orig/gcc/cp/decl.cc 2025-04-25 17:18:00 +0900 +++ gcc-15.1.0/gcc/cp/decl.cc 2026-05-15 00:19:42 +0900 @@ -13850,7 +13850,7 @@ auto_diagnostic_group d; if (warning_at (declarator->parenthesized, OPT_Wparentheses, "unnecessary parentheses in declaration of %qs", - name)) + name) && false) { gcc_rich_location iloc (declarator->parenthesized); iloc.add_fixit_remove (get_start (declarator->parenthesized)); diff -urN gcc-15.1.0-orig/gcc/cp/error.cc gcc-15.1.0/gcc/cp/error.cc --- gcc-15.1.0-orig/gcc/cp/error.cc 2025-04-25 17:18:00 +0900 +++ gcc-15.1.0/gcc/cp/error.cc 2026-05-15 01:01:49 +0900 @@ -40,6 +40,7 @@ #include "pretty-print-format-impl.h" #include "make-unique.h" #include "diagnostic-format-text.h" +#include "flags.h" #define pp_separate_with_comma(PP) pp_cxx_separate_with (PP, ',') #define pp_separate_with_semicolon(PP) pp_cxx_separate_with (PP, ';') @@ -4887,7 +4888,7 @@ name_hint hint; if (SCOPED_ENUM_P (scope) && TREE_CODE (name) == IDENTIFIER_NODE) hint = suggest_alternative_in_scoped_enum (name, scope); - if (const char *suggestion = hint.suggestion ()) + if (const char *suggestion = hint.suggestion (); flag_diagnostics_add_fixits) { gcc_rich_location richloc (location); richloc.add_fixit_replace (suggestion); @@ -4913,7 +4914,7 @@ fix-it hints for the suggestion. */ emit_fixit = false; } - if (const char *suggestion = hint.suggestion ()) + if (const char *suggestion = hint.suggestion (); flag_diagnostics_add_fixits) { gcc_rich_location richloc (location); if (emit_fixit) @@ -4928,7 +4929,7 @@ { auto_diagnostic_group d; name_hint hint = suggest_alternatives_for (location, name, true); - if (const char *suggestion = hint.suggestion ()) + if (const char *suggestion = hint.suggestion (); flag_diagnostics_add_fixits) { gcc_rich_location richloc (location); richloc.add_fixit_replace (suggestion); diff -urN gcc-15.1.0-orig/gcc/cp/lex.cc gcc-15.1.0/gcc/cp/lex.cc --- gcc-15.1.0-orig/gcc/cp/lex.cc 2025-04-25 17:18:00 +0900 +++ gcc-15.1.0/gcc/cp/lex.cc 2026-05-15 01:01:43 +0900 @@ -32,6 +32,7 @@ #include "gcc-rich-location.h" #include "cp-name-hint.h" #include "langhooks.h" +#include "flags.h" static int interface_strcmp (const char *); static void init_cp_traits (void); @@ -755,7 +756,7 @@ { auto_diagnostic_group d; name_hint hint = suggest_alternatives_for (loc, name, true); - if (const char *suggestion = hint.suggestion ()) + if (const char *suggestion = hint.suggestion (); flag_diagnostics_add_fixits) { gcc_rich_location richloc (loc); richloc.add_fixit_replace (suggestion); diff -urN gcc-15.1.0-orig/gcc/cp/typeck.cc gcc-15.1.0/gcc/cp/typeck.cc --- gcc-15.1.0-orig/gcc/cp/typeck.cc 2025-04-25 17:18:00 +0900 +++ gcc-15.1.0/gcc/cp/typeck.cc 2026-05-15 01:01:36 +0900 @@ -40,6 +40,7 @@ #include "attribs.h" #include "asan.h" #include "gimplify.h" +#include "flags.h" static tree cp_build_addr_expr_strict (tree, tsubst_flags_t); static tree cp_build_function_call (tree, tree, tsubst_flags_t); @@ -3267,6 +3268,9 @@ void access_failure_info::maybe_suggest_accessor (bool const_p) const { + if (!flag_diagnostics_add_fixits) + return; + tree accessor = get_any_accessor (const_p); if (accessor == NULL_TREE) return; @@ -3288,7 +3292,7 @@ /* Attempt to provide a hint about misspelled names. */ tree guessed_id = lookup_member_fuzzy (access_path, name, /*want_type=*/false); - if (guessed_id == NULL_TREE) + if (guessed_id == NULL_TREE || !flag_diagnostics_add_fixits) { /* No hint. */ error ("%q#T has no member named %qE", diff -urN gcc-15.1.0-orig/gcc/cp/typeck2.cc gcc-15.1.0/gcc/cp/typeck2.cc --- gcc-15.1.0-orig/gcc/cp/typeck2.cc 2025-04-25 17:18:00 +0900 +++ gcc-15.1.0/gcc/cp/typeck2.cc 2026-05-15 01:01:29 +0900 @@ -34,6 +34,7 @@ #include "intl.h" #include "gcc-rich-location.h" #include "target.h" +#include "flags.h" static tree process_init_constructor (tree type, tree init, int nested, int flags, @@ -359,7 +360,7 @@ member = MAYBE_BASELINK_FUNCTIONS (member); if (TREE_CODE (member) == FUNCTION_DECL && DECL_OBJECT_MEMBER_FUNCTION_P (member) - && type_num_arguments (TREE_TYPE (member)) == 1) + && type_num_arguments (TREE_TYPE (member)) == 1 && flag_diagnostics_add_fixits) richloc.add_fixit_insert_after ("()"); complained = emit_diagnostic (diag_kind, &richloc, 0, "invalid use of member function %qD "