[Bug c++/61339] add mismatch between struct and class [-Wmismatched-tags] to non-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61339 --- Comment #16 from Martin Sebor --- Author: msebor Date: Tue Dec 17 23:53:07 2019 New Revision: 279480 URL: https://gcc.gnu.org/viewcvs?rev=279480&root=gcc&view=rev Log: PR c++/61339 - add warning for mismatch between struct and class gcc/c-family/ChangeLog: PR c++/61339 * c.opt (-Wmismatched-tags, -Wredundant-tags): New options. gcc/cp/ChangeLog: PR c++/61339 * parser.c (cp_parser_maybe_warn_enum_key): New function. (class_decl_loc_t): New class. (cp_parser_elaborated_type_specifier): Call cp_parser_maybe_warn_enum_key. (cp_parser_class_head): Call cp_parser_check_class_key. (cp_parser_check_class_key): Add arguments. Call class_decl_loc_t::add. (c_parse_file): Call class_decl_loc_t::diag_mismatched_tags. gcc/testsuite/ChangeLog: PR c++/61339 * g++.dg/warn/Wmismatched-tags.C: New test. * g++.dg/warn/Wredundant-tags.C: New test. * g++.dg/pch/Wmismatched-tags.C: New test. * g++.dg/pch/Wmismatched-tags.Hs: New test header. gcc/ChangeLog: PR c++/61339 * doc/invoke.texi (-Wmismatched-tags, -Wredundant-tags): Document new C++ options. Added: trunk/gcc/testsuite/g++.dg/pch/Wmismatched-tags.C trunk/gcc/testsuite/g++.dg/pch/Wmismatched-tags.Hs trunk/gcc/testsuite/g++.dg/warn/Wmismatched-tags.C trunk/gcc/testsuite/g++.dg/warn/Wredundant-tags.C Modified: trunk/gcc/ChangeLog trunk/gcc/c-family/ChangeLog trunk/gcc/c-family/c.opt trunk/gcc/cp/ChangeLog trunk/gcc/cp/parser.c trunk/gcc/doc/invoke.texi trunk/gcc/testsuite/ChangeLog
[Bug c++/61339] add mismatch between struct and class [-Wmismatched-tags] to non-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61339 --- Comment #15 from Martin Sebor --- (In reply to Eric Gallager from comment #14) The patch that implements -Wmismatched-tags is still in review. Here's the latest: https://gcc.gnu.org/ml/gcc-patches/2019-12/msg01154.html
[Bug c++/61339] add mismatch between struct and class [-Wmismatched-tags] to non-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61339 --- Comment #14 from Eric Gallager --- (In reply to Martin Sebor from comment #13) > Author: msebor > Date: Tue Jul 9 18:32:49 2019 > New Revision: 273311 > > URL: https://gcc.gnu.org/viewcvs?rev=273311&root=gcc&view=rev > Log: > PR c++/61339 - add mismatch between struct and class [-Wmismatched-tags] to > non-bugs > [...snip...] This is just dealing with the fallout that WOULD occur if we were to add the warning, right? i.e., it didn't actually add the warning itself?
[Bug c++/61339] add mismatch between struct and class [-Wmismatched-tags] to non-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61339 --- Comment #13 from Martin Sebor --- Author: msebor Date: Tue Jul 9 18:32:49 2019 New Revision: 273311 URL: https://gcc.gnu.org/viewcvs?rev=273311&root=gcc&view=rev Log: PR c++/61339 - add mismatch between struct and class [-Wmismatched-tags] to non-bugs gcc/c/ChangeLog: PR c++/61339 * c-decl.c (xref_tag): Change class-key of PODs to struct and others to class. (field_decl_cmp): Same. * c-parser.c (c_parser_struct_or_union_specifier): Same. * c-tree.h: Same. * gimple-parser.c (c_parser_gimple_compound_statement): Same. gcc/c-family/ChangeLog: PR c++/61339 * c-opts.c (handle_deferred_opts): : Change class-key of PODs to struct and others to class. * c-pretty-print.h: Same. gcc/cp/ChangeLog: PR c++/61339 * cp-tree.h: Change class-key of PODs to struct and others to class. * search.c: Same. * semantics.c (finalize_nrv_r): Same. gcc/lto/ChangeLog: PR c++/61339 * lto-common.c (lto_splay_tree_new): : Change class-key of PODs to struct and others to class. (mentions_vars_p): Same. (register_resolution): Same. (lto_register_var_decl_in_symtab): Same. (lto_register_function_decl_in_symtab): Same. (cmp_tree): Same. (lto_read_decls): Same. gcc/ChangeLog: PR c++/61339 * auto-profile.c: Change class-key of PODs to struct and others to class. * basic-block.h: Same. * bitmap.c (bitmap_alloc): Same. * bitmap.h: Same. * builtins.c (expand_builtin_prefetch): Same. (expand_builtin_interclass_mathfn): Same. (expand_builtin_strlen): Same. (expand_builtin_mempcpy_args): Same. (expand_cmpstr): Same. (expand_builtin___clear_cache): Same. (expand_ifn_atomic_bit_test_and): Same. (expand_builtin_thread_pointer): Same. (expand_builtin_set_thread_pointer): Same. * caller-save.c (setup_save_areas): Same. (replace_reg_with_saved_mem): Same. (insert_restore): Same. (insert_save): Same. (add_used_regs): Same. * cfg.c (get_bb_copy): Same. (set_loop_copy): Same. * cfg.h: Same. * cfganal.h: Same. * cfgexpand.c (alloc_stack_frame_space): Same. (add_stack_var): Same. (add_stack_var_conflict): Same. (add_scope_conflicts_1): Same. (update_alias_info_with_stack_vars): Same. (expand_used_vars): Same. * cfghooks.c (redirect_edge_and_branch_force): Same. (delete_basic_block): Same. (split_edge): Same. (make_forwarder_block): Same. (force_nonfallthru): Same. (duplicate_block): Same. (lv_flush_pending_stmts): Same. * cfghooks.h: Same. * cfgloop.c (flow_loops_cfg_dump): Same. (flow_loop_nested_p): Same. (superloop_at_depth): Same. (get_loop_latch_edges): Same. (flow_loop_dump): Same. (flow_loops_dump): Same. (flow_loops_free): Same. (flow_loop_nodes_find): Same. (establish_preds): Same. (flow_loop_tree_node_add): Same. (flow_loop_tree_node_remove): Same. (flow_loops_find): Same. (find_subloop_latch_edge_by_profile): Same. (find_subloop_latch_edge_by_ivs): Same. (mfb_redirect_edges_in_set): Same. (form_subloop): Same. (merge_latch_edges): Same. (disambiguate_multiple_latches): Same. (disambiguate_loops_with_multiple_latches): Same. (flow_bb_inside_loop_p): Same. (glb_enum_p): Same. (get_loop_body_with_size): Same. (get_loop_body): Same. (fill_sons_in_loop): Same. (get_loop_body_in_dom_order): Same. (get_loop_body_in_custom_order): Same. (release_recorded_exits): Same. (get_loop_exit_edges): Same. (num_loop_branches): Same. (remove_bb_from_loops): Same. (find_common_loop): Same. (delete_loop): Same. (cancel_loop): Same. (verify_loop_structure): Same. (loop_preheader_edge): Same. (loop_exit_edge_p): Same. (single_exit): Same. (loop_exits_to_bb_p): Same. (loop_exits_from_bb_p): Same. (get_loop_location): Same. (record_niter_bound): Same. (get_estimated_loop_iterations_int): Same. (max_stmt_executions_int): Same. (likely_max_stmt_executions_int): Same. (get_estimated_loop_iterations): Same. (get_max_loop_iterations): Same. (get_max_loop_iterations_int): Same. (get_likely_max_loop_iterations): Same. * cfgloop.h (simple_loop_desc): Same. (get_loop): Same. (loop_depth): Same. (loop_outer): Same. (loop_iterator::next): Same. (loop_outermost): Same. * cfgloopanal.c (mark_irreduci
[Bug c++/61339] add mismatch between struct and class [-Wmismatched-tags] to non-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61339 --- Comment #12 from Martin Sebor --- Author: msebor Date: Tue Jul 9 16:36:00 2019 New Revision: 273308 URL: https://gcc.gnu.org/viewcvs?rev=273308&root=gcc&view=rev Log: PR c++/61339 - add mismatch between struct and class [-Wmismatched-tags] to non-bugs gcc/c/ChangeLog: PR c++/61339 * c-decl.c: Change class-key from class to struct and vice versa to match convention and avoid -Wclass-is-pod and -Wstruct-no-pod. * gimple-parser.c: Same. gcc/c-family/ChangeLog: PR c++/61339 * c-format.c (check_argument_type): Change class-key from class to struct and vice versa to match convention and avoid -Wclass-is-pod and -Wstruct-no-pod. * c-pretty-print.h: Same. gcc/cp/ChangeLog: PR c++/61339 * constexpr.c (cxx_eval_call_expression): Change class-key from class to struct and vice versa to match convention and avoid -Wclass-is-pod and -Wstruct-no-pod. * constraint.cc (get_concept_definition): Same. * cp-tree.h: Same. * cxx-pretty-print.h: Same. * error.c: Same. * logic.cc (term_list::replace): Same. * name-lookup.c (find_local_binding): Same. * pt.c (tsubst_binary_right_fold): Same. * search.c (field_accessor_p): Same. * semantics.c (expand_or_defer_fn): Same. gcc/lto/ChangeLog: PR c++/61339 * lto-dump.c: Change class-key from classi to struct and vice versa to match convention and avoid -Wclass-is-pod and -Wstruct-no-pod. gcc/ChangeLog: PR c++/61339 * align.h: Change class-key from class to struct and vice versa to match convention and avoid -Wclass-is-pod and -Wstruct-no-pod. * alloc-pool.h: Same. * asan.c (shadow_mem_size): Same. * auto-profile.c: Same. * basic-block.h: Same. * bitmap.h: Same. * cfgexpand.c (set_rtl): Same. (expand_one_stack_var_at): Same. * cfghooks.h: Same. * cfgloop.h: Same. * cgraph.h: Same. * config/i386/i386.h: Same. * df-problems.c (df_print_bb_index): Same. * df-scan.c: Same. * df.h (df_single_use): Same. * diagnostic-show-locus.c (layout::print_annotation_line): Same. (layout::annotation_line_showed_range_p): Same. (get_printed_columns): Same. (correction::ensure_terminated): Same. (line_corrections::~line_corrections): Same. * dojump.h: Same. * dse.c: Same. * dump-context.h: Same. * dumpfile.h: Same. * dwarf2out.c: Same. * edit-context.c: Same. * fibonacci_heap.c (test_union_of_equal_heaps): Same. * flags.h: Same. * function.c (assign_stack_local): Same. * function.h: Same. * gcc.c: Same. * gcov.c (block_info::block_info): Same. * genattrtab.c: Same. * genextract.c: Same. * genmatch.c (comparison_code_p): Same. (id_base::id_base): Same. (decision_tree::print): Same. * genoutput.c: Same. * genpreds.c (write_one_predicate_function): Same. * genrecog.c (validate_pattern): Same. (find_operand_positions): Same. (optimize_subroutine_group): Same. (merge_pattern_transition::merge_pattern_transition): Same. (merge_pattern_info::merge_pattern_info): Same. (merge_state_result::merge_state_result): Same. (merge_into_state): Same. * gensupport.c: Same. * gensupport.h: Same. * ggc-common.c (init_ggc_heuristics): Same. * ggc-tests.c (test_union): Same. * gimple-loop-interchange.cc (dump_induction): Same. * gimple-loop-versioning.cc: Same. * gimple-match.h (gimple_match_cond::any_else): Same. * gimple-ssa-backprop.c: Same. * gimple-ssa-sprintf.c: Same. * gimple-ssa-store-merging.c (store_operand_info::store_operand_info): Same. (store_immediate_info::store_immediate_info): Same. (merged_store_group::apply_stores): Same. (get_location_for_stmts): Same. * gimple-ssa-strength-reduction.c: Same. * gimple-ssa-warn-alloca.c: Same. * gimple-ssa-warn-restrict.c (pass_wrestrict::execute): Same. * godump.c (go_type_decl): Same. * hash-map-tests.c (test_map_of_strings_to_int): Same. * hash-map.h: Same. * hash-set-tests.c (test_set_of_strings): Same. * hsa-brig.c: Same. * hsa-common.h: Same. * hsa-gen.c (transformable_switch_to_sbr_p): Same. * input.c (assert_loceq): Same. * input.h: Same. * ipa-cp.c: Same. * ipa-devirt.c (possible_polymorphic_call_targets_1): Same. * ipa-fnsummary.h: Same. * ipa-inline.h: Same. * ipa-prop.h: Same. * ipa-split.c (visit_bb): Same. * ira-int.h (minmax_set_iter_next): Same. * loop-invarian
[Bug c++/61339] add mismatch between struct and class [-Wmismatched-tags] to non-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61339 Martin Sebor changed: What|Removed |Added Keywords||patch --- Comment #11 from Martin Sebor --- Patch: https://gcc.gnu.org/ml/gcc-patches/2019-07/msg00621.html
[Bug c++/61339] add mismatch between struct and class [-Wmismatched-tags] to non-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61339 Martin Sebor changed: What|Removed |Added Status|NEW |ASSIGNED Assignee|unassigned at gcc dot gnu.org |msebor at gcc dot gnu.org --- Comment #10 from Martin Sebor --- Testing a patch.
[Bug c++/61339] add mismatch between struct and class [-Wmismatched-tags] to non-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61339 --- Comment #9 from Martin Sebor --- The warning I prototyped is meant to help enforce the GCC coding convention to "use the struct keyword for plain old data (POD) types." Depending on how strictly the sentence is interpreted the warning would detect a smaller or bigger subset of the -Wmismatched-tags instances. If the word "use" is meant "in definitions use" the set would be smaller; if it's meant "in declarations use" then the warning would actually detect a superset of -Wmismatched-tags instances. The convention doesn't seem to speak to template classes that are POD only if instantiated on POD types.
[Bug c++/61339] add mismatch between struct and class [-Wmismatched-tags] to non-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61339 Eric Gallager changed: What|Removed |Added CC||msebor at gcc dot gnu.org --- Comment #8 from Eric Gallager --- (In reply to Eric Gallager from comment #7) > Regardless of compatibility with MS, writing code consistently makes things > easier for human readers to follow, and should be encouraged. At least IMO. Apparently Martin Sebor agrees and has started work on a similar warning: https://gcc.gnu.org/ml/gcc-patches/2019-06/msg01853.html
[Bug c++/61339] add mismatch between struct and class [-Wmismatched-tags] to non-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61339 Eric Gallager changed: What|Removed |Added CC||egallager at gcc dot gnu.org Summary|add mismatch between struct |add mismatch between struct |and class to non-bugs |and class ||[-Wmismatched-tags] to ||non-bugs --- Comment #7 from Eric Gallager --- Regardless of compatibility with MS, writing code consistently makes things easier for human readers to follow, and should be encouraged. At least IMO.