aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp
AgeCommit message (Collapse)AuthorFilesLines
2018-09-10class.c (build_vtbl_ref): Remove.Marek Polacek2-13/+9
* class.c (build_vtbl_ref): Remove. (build_vtbl_ref_1): Rename to build_vtbl_ref. (build_vfn_ref): Call build_vtbl_ref instead of build_vtbl_ref_1. From-SVN: r264193
2018-09-08PR c++/87150 - wrong ctor with maybe-rvalue semantics.Marek Polacek2-3/+13
* call.c (struct conversion): Update commentary. (standard_conversion): Set rvaluedness_matches_p if LOOKUP_PREFER_RVALUE for ck_base. * g++.dg/cpp0x/move-return2.C: New test. From-SVN: r264172
2018-09-08PR c++/86678 - constexpr function with non-constant after return.Jason Merrill2-13/+60
In this testcase, the call to f() can never be a constant expression, but that's not a problem because it isn't always reached by calls to g. We were wrongly rejecting this because potential_constant_expression_1 lacked the jump tracking that cxx_eval_constant_expression has. So this patch adds a simpler version of that tracking. * constexpr.c (potential_constant_expression_1): Add jump_target. (breaks): Check for BREAK_STMT. (continues): Check for CONTINUE_STMT. From-SVN: r264171
2018-09-08cxx-pretty-print.c (cxx_pretty_printer::statement): Handle RANGE_FOR_INIT_STMT.Marek Polacek2-0/+11
* cxx-pretty-print.c (cxx_pretty_printer::statement) <case RANGE_FOR_SMT>: Handle RANGE_FOR_INIT_STMT. From-SVN: r264170
2018-09-07PR c++/87152 - range-based for loops with initializer broken in templates.Marek Polacek7-10/+32
* constexpr.c (potential_constant_expression_1) <case RANGE_FOR_STMT>: Recur into RANGE_FOR_INIT_STMT. * cp-tree.def: Add RANGE_FOR_INIT_STMT to RANGE_FOR_STMT. * cp-tree.h (RANGE_FOR_INIT_STMT): Define. * dump.c (cp_dump_tree) <case RANGE_FOR_STMT>: Also dump RANGE_FOR_INIT_STMT. * pt.c (tsubst_expr) <case RANGE_FOR_STMT>: Recur into RANGE_FOR_INIT_STMT. * semantics.c (begin_range_for_stmt): Adjust call to build_stmt. Do put the init statement in RANGE_FOR_INIT_STMT. (finish_range_for_decl): Pop it for templates. * g++.dg/cpp2a/range-for11.C: New test. * g++.dg/cpp2a/range-for12.C: New test. * g++.dg/cpp2a/range-for13.C: New test. * g++.dg/cpp2a/range-for14.C: New test. * g++.dg/cpp2a/range-for15.C: New test. * g++.dg/cpp2a/range-for16.C: New test. * g++.dg/cpp2a/range-for17.C: New test. * g++.dg/cpp2a/range-for18.C: New test. * g++.dg/parse/error61.C (foo): Adjust dg-error. From-SVN: r264158
2018-09-06varasm.c (output_constructor_regular_field): Check TYPE_SIZE_UNIT of the ↵Bernd Edlinger2-0/+14
init value. * varasm.c (output_constructor_regular_field): Check TYPE_SIZE_UNIT of the init value. * c-common.c (complete_flexible_array_elts): New helper function. * c-common.h (complete_flexible_array_elts): Declare. * c-decl.c (finish_decl): Call complete_flexible_array_elts. * decl.c (check_initializer): Call cp_complete_array_type. From-SVN: r264147
2018-09-06PR c++/86982, -Wreturn-local-addr and std::move and std::forward.Marek Polacek2-0/+33
* typeck.c (maybe_warn_about_returning_address_of_local): Handle calls to std::move or std::forward. (is_std_forward_p): New function. * g++.dg/warn/Wreturn-local-addr-5.C: New test. From-SVN: r264139
2018-09-05PR c++/87109, wrong overload with ref-qualifiers.Marek Polacek2-2/+15
* call.c (build_user_type_conversion_1): Use NULL instead of 0. Bail out if performing the maybe-rvalue overload resolution and a conversion function is getting called. * g++.dg/cpp0x/ref-qual19.C: New test. From-SVN: r264132
2018-09-05[PR c++/87185] ICE in prune-lambdasPádraig Brady2-3/+9
https://gcc.gnu.org/ml/gcc-patches/2018-09/msg00249.html cp/ PR c++/87185 * lambda.c (prune_lambda_captures): Protect against const_vars.get returning NULL. testsuite/ PR c++/87185 * g++.dg/pr87185.C: New. From-SVN: r264118
2018-09-05cp-tree.h (treat_lvalue_as_rvalue_p): Declare.Marek Polacek4-11/+19
* cp-tree.h (treat_lvalue_as_rvalue_p): Declare. * except.c (build_throw): Use it. Use CP_TYPE_VOLATILE_P. * typeck.c (treat_lvalue_as_rvalue_p): No longer static. Add PARM_OK parameter. (maybe_warn_pessimizing_move): Adjust treat_lvalue_as_rvalue_p call. (check_return_expr): Likewise. From-SVN: r264101
2018-09-03re PR c++/84980 ([concepts] ICE with missing typename in concept)Paolo Carlini2-0/+9
/cp 2018-09-03 Paolo Carlini <paolo.carlini@oracle.com> PR c++/84980 * constraint.cc (finish_shorthand_constraint): Early return if the constraint is erroneous. /testsuite 2018-09-03 Paolo Carlini <paolo.carlini@oracle.com> PR c++/84980 * g++.dg/concepts/pr84980.C: New. From-SVN: r264051
2018-09-02c-common.c (braced_list_to_string): Remove eval parameter.Bernd Edlinger3-38/+14
* c-common.c (braced_list_to_string): Remove eval parameter. Add some more checks. Always create zero-terminated STRING_CST. * c-common.h (braced_list_to_string): Adjust prototype. * c-decl.c (finish_decl): Call braced_list_to_string here ... * c-parser.c (c_parser_declaration_or_fndef): ... instead of here. * decl.c (eval_check_narrowing): Remove. (check_initializer): Move call to braced_list_to_string from here ... * typeck2.c (store_init_value): ... to here. (digest_init_r): Remove handing of signed/unsigned char strings. * c-c++-common/array-init.c: New test. * g++.dg/init/string2.C: Remove xfail. From-SVN: r264042
2018-08-31[PR c++/87155] Anonymous namespace andNathan Sidwell2-5/+13
https://gcc.gnu.org/ml/gcc-patches/2018-08/msg02031.html PR c++/87155 PR c++/84707 cp/ * name-lookup.c (name_lookup::search_namespace): Don't look at inlines when searching for NULL names. testsuite/ * g++.dg/cpp0x/pr87155.C: New. * g++.dg/cpp0x/inline-ns10.C: Adjust. From-SVN: r264016
2018-08-31[C++ PATCH] Remove K&R declaration hack.Nathan Sidwell3-29/+9
https://gcc.gnu.org/ml/gcc-patches/2018-08/msg01885.html gcc/ * doc/extend.texi (Backwards Compatibility): Remove implicit extern C leeway of () being (...). gcc/cp/ * decl.c (decls_match): Remove SYSTEM_IMPLICIT_EXTERN_C matching of return types and parms. * parser.c (cp_parser_parameter_declaration_clause): Likewise, '()' always means '(void)'. From-SVN: r264013
2018-08-29re PR sanitizer/87095 (UndefinedBehaviorSanitizer vptr false positive with ↵Jakub Jelinek2-0/+20
virtual inheritance only with -fno-sanitize-recover) PR c++/87095 * decl.c (begin_destructor_body): If current_class_type has virtual bases and the primary base is nearly empty virtual base, voidify clearing of vptr and make it conditional on in-charge argument. * g++.dg/ubsan/vptr-13.C: New test. From-SVN: r263967
2018-08-29re PR c++/85265 ([concepts] ICE with missing identifier)Paolo Carlini2-6/+18
/cp 2018-08-29 Paolo Carlini <paolo.carlini@oracle.com> PR c++/85265 * parser.c (cp_parser_introduction_list): If cp_parser_identifier returns error_mark_node early exit the loop. (cp_parser_template_introduction): Improve error-recovery, remove error call about empty introduction-list. /testsuite 2018-08-29 Paolo Carlini <paolo.carlini@oracle.com> PR c++/85265 * g++.dg/concepts/pr85265.C: New. From-SVN: r263966
2018-08-29C++: underline param in print_conversion_rejection (more PR c++/85110)David Malcolm2-6/+19
Consider this bogus code (from g++.dg/diagnostic/param-type-mismatch-2.C): struct s4 { static int member_1 (int one, const char **two, float three); }; int test_4 (int first, const char *second, float third) { return s4::member_1 (first, second, third); } Before this patch, g++ emits: demo.cc: In function 'int test_4(int, const char*, float)': demo.cc:5:44: error: no matching function for call to 's4::member_1(int&, const char*&, float&)' 5 | return s4::member_1 (first, second, third); | ^ demo.cc:1:24: note: candidate: 'static int s4::member_1(int, const char**, float)' 1 | struct s4 { static int member_1 (int one, const char **two, float three); }; | ^~~~~~~~ demo.cc:1:24: note: no known conversion for argument 2 from 'const char*' to 'const char**' With this patch, it highlights the pertinent parameter in the "no known conversion" note: demo.cc: In function 'int test_4(int, const char*, float)': demo.cc:5:44: error: no matching function for call to 's4::member_1(int&, const char*&, float&)' 5 | return s4::member_1 (first, second, third); | ^ demo.cc:1:24: note: candidate: 'static int s4::member_1(int, const char**, float)' 1 | struct s4 { static int member_1 (int one, const char **two, float three); }; | ^~~~~~~~ demo.cc:1:56: note: no known conversion for argument 2 from 'const char*' to 'const char**' 1 | struct s4 { static int member_1 (int one, const char **two, float three); }; | ~~~~~~~~~~~~~^~~ gcc/cp/ChangeLog: PR c++/85110 * call.c (print_conversion_rejection): Add "fn" param and use it for "no known conversion" messages to underline the pertinent param. (print_z_candidate): Supply "fn" to the new param above. gcc/testsuite/ChangeLog: PR c++/85110 * g++.dg/diagnostic/param-type-mismatch-2.C: Update expected output to reflect underlining of pertinent parameter in decl for "no known conversion" messages. From-SVN: r263957
2018-08-29re PR c++/87122 (ICE in tsubst_decomp_names)Jakub Jelinek2-0/+9
PR c++/87122 * pt.c (tsubst_expr) <case RANGE_FOR_STMT>: If processing_template_decl and decl is structured binding decl, call cp_finish_decomp. * g++.dg/cpp1z/decomp47.C: New test. From-SVN: r263953
2018-08-28remove utf-8 from commentJason Merrill1-1/+1
From-SVN: r263942
2018-08-28re PR c++/86546 (ICE on invalid: tree_class_check_failed())Paolo Carlini2-0/+8
/cp 2018-08-28 Paolo Carlini <paolo.carlini@oracle.com> PR c++/86546 * decl.c (finish_case_label): If the type is erroneous early return error_mark_node. /testsuite 2018-08-28 Paolo Carlini <paolo.carlini@oracle.com> PR c++/86546 * g++.dg/other/switch4.C: New. From-SVN: r263921
2018-08-27C++: fix-it hint for missing "typename" (PR c++/63392)David Malcolm2-2/+10
This patch adds a fix-it hint to missing "typename" errors in the C++ frontend, suggesting the insertion of "typename ". This addresses part of PR c++/63392; however it does not improve the error-recovery for such cases. gcc/cp/ChangeLog: PR c++/63392 * parser.c (cp_parser_diagnose_invalid_type_name): Add fix-it hint. gcc/testsuite/ChangeLog: PR c++/63392 * g++.dg/diagnostic/missing-typename.C: New test. From-SVN: r263899
2018-08-27re PR c++/86993 (assignment of read-only variable error reported at wrong ↵Jakub Jelinek5-33/+41
location) PR c++/86993 * cp-tree.h (cxx_readonly_error): Add location_t argument. * typeck2.c (cxx_readonly_error): Add LOC argument, pass it to ERROR_FOR_ASSIGNMENT macro and readonly_error. Add LOC argument to ERROR_FOR_ASSIGNMENT macro, use error_at instead of error and pass LOC to it. Formatting fixes. * typeck.c (cp_build_unary_op): Pass location to cxx_readonly_error. (cp_build_modify_expr): Pass loc to cxx_readonly_error. * semantics.c (finish_asm_stmt): Pass input_location to cxx_readonly_error. * g++.dg/diagnostic/pr86993.C: New test. From-SVN: r263891
2018-08-27Replace 8 spaces with a tabular in ChangeLog files.Martin Liska1-5/+5
From-SVN: r263886
2018-08-27Less verbose fix-it hints for missing header files (PR 87091)David Malcolm7-12/+29
This patch tweaks maybe_add_include_fixit so that if we're emitting a note about adding the header file, the note's primary location will be replaced by that of the fix-it hint, to avoid repeating a location we've already emitted (or one close to it). For example, this simplifies: ../x86_64-pc-linux-gnu/libstdc++-v3/include/vector:87:27: error: msg 1 87 | using vector = std::vector<_Tp, polymorphic_allocator<_Tp>>; | ^~~~~~ ../x86_64-pc-linux-gnu/libstdc++-v3/include/vector:87:22: note: msg 2 73 | # include <debug/vector> +++ |+#include <vector> 74 | #endif .... 87 | using vector = std::vector<_Tp, polymorphic_allocator<_Tp>>; | ^~~ to: ../x86_64-pc-linux-gnu/libstdc++-v3/include/vector:87:27: error: msg 1 87 | using vector = std::vector<_Tp, polymorphic_allocator<_Tp>>; | ^~~~~~ ../x86_64-pc-linux-gnu/libstdc++-v3/include/vector:74:1: note: msg 2 73 | # include <debug/vector> +++ |+#include <vector> 74 | #endif eliminating the repetition of line 87 in the note. Doing so requires converting show_caret_p to a tri-state, to avoid meaninglessly printing a caret for the first column in the next line (and colorizing it): ../x86_64-pc-linux-gnu/libstdc++-v3/include/vector:74:1: note: msg 2 73 | # include <debug/vector> +++ |+#include <vector> 74 | #endif | ^ gcc/c-family/ChangeLog: PR 87091 * c-common.c (c_cpp_error): Update for conversion of show_caret_p to a tri-state. (maybe_suggest_missing_token_insertion): Likewise. (maybe_add_include_fixit): Add param "override_location". If set, and source-printing is enabled, then override the rich_location's primary location with that of the insertion point for the fix-it hint, marking it with SHOW_LINES_WITHOUT_RANGE. * c-common.h (extern void maybe_add_include_fixit): Add bool param. * c-format.c (selftest::test_type_mismatch_range_labels): Update for conversion of show_caret_p to a tri-state. * c-warn.c (warn_for_restrict): Likewise. * known-headers.cc (suggest_missing_header::~suggest_missing_header): Update call to maybe_add_include_fixit to suggest overriding the location, as it is for a note. gcc/c/ChangeLog: PR 87091 * c-decl.c (implicitly_declare): Update call to maybe_add_include_fixit to suggest overriding the location, as it is for a note. * c-objc-common.c (c_tree_printer): Update for conversion of show_caret_p to a tri-state. gcc/cp/ChangeLog: PR 87091 * decl.c (grokdeclarator): Update for conversion of show_caret_p to a tri-state. * error.c (cp_printer): Likewise. * name-lookup.c (maybe_suggest_missing_std_header): Update call to maybe_add_include_fixit to suggest overriding the location, as it is for a note. * parser.c (cp_parser_string_literal): Update for conversion of show_caret_p to a tri-state. (cp_parser_elaborated_type_specifier): Likewise. (set_and_check_decl_spec_loc): Likewise. * pt.c (listify): Update call to maybe_add_include_fixit to not override the location, as it is for an error. * rtti.c (typeid_ok_p): Likewise. gcc/ChangeLog: PR 87091 * diagnostic-show-locus.c (class layout_range): Update for conversion of show_caret_p to a tri-state. (layout_range::layout_range): Likewise. (make_range): Likewise. (layout::maybe_add_location_range): Likewise. (layout::should_print_annotation_line_p): Don't show annotation lines for ranges that are SHOW_LINES_WITHOUT_RANGE. (layout::get_state_at_point): Update for conversion of show_caret_p to a tri-state. Bail out early for SHOW_LINES_WITHOUT_RANGE, so that such ranges don't affect underlining or source colorization. (gcc_rich_location::add_location_if_nearby): Update for conversion of show_caret_p to a tri-state. (selftest::test_one_liner_multiple_carets_and_ranges): Likewise. (selftest::test_one_liner_fixit_replace_equal_secondary_range): Likewise. (selftest::test_one_liner_labels): Likewise. * gcc-rich-location.c (gcc_rich_location::add_expr): Update for conversion of show_caret_p to a tri-state. * pretty-print.c (text_info::set_location): Likewise. * pretty-print.h (text_info::set_location): Likewise. * substring-locations.c (format_warning_n_va): Likewise. * tree-diagnostic.c (default_tree_printer): Likewise. * tree-pretty-print.c (newline_and_indent): Likewise. gcc/fortran/ChangeLog: PR 87091 * error.c (gfc_format_decoder): Update for conversion of show_caret_p to a tri-state. gcc/testsuite/ChangeLog: PR 87091 * gcc.dg/empty.h: New file. * gcc.dg/fixits-pr84852-1.c: Update for move of fix-it hint to top of file and removal of redundant second printing of warning location. * gcc.dg/fixits-pr84852-2.c: Likewise. * gcc.dg/missing-header-fixit-3.c: Likewise. * gcc.dg/missing-header-fixit-4.c: New test. * gcc.dg/plugin/diagnostic_plugin_test_show_locus.c: Update for conversion of show_caret_p to a tri-state. libcpp/ChangeLog: PR 87091 * include/line-map.h (enum range_display_kind): New enum. (struct location_range): Replace field "m_show_caret_p" with "m_range_display_kind", converting from bool to the new enum. (class rich_location): Add example of line insertion fix-it hint. (rich_location::add_range): Convert param "show_caret_p" from bool to enum range_display_kind and rename to "range_display_kind", giving it a default of SHOW_RANGE_WITHOUT_CARET. (rich_location::set_range): Likewise, albeit without a default. * line-map.c (rich_location::rich_location): Update for conversion of show_caret_p to tri-state enum. (rich_location::add_range): Likewise. (rich_location::set_range): Likewise. From-SVN: r263885
2018-08-27Come up with fndecl_built_in_p.Martin Liska8-35/+49
2018-08-27 Martin Liska <mliska@suse.cz> * builtins.h (is_builtin_fn): Remove and fndecl_built_in_p. * builtins.c (is_builtin_fn): Likewise. * attribs.c (diag_attr_exclusions): Use new function fndecl_built_in_p and remove check for FUNCTION_DECL if possible. (builtin_mathfn_code): Likewise. (fold_builtin_expect): Likewise. (fold_call_expr): Likewise. (fold_builtin_call_array): Likewise. (fold_call_stmt): Likewise. (set_builtin_user_assembler_name): Likewise. (is_simple_builtin): Likewise. * calls.c (gimple_alloca_call_p): Likewise. (maybe_warn_nonstring_arg): Likewise. * cfgexpand.c (expand_call_stmt): Likewise. * cgraph.c (cgraph_update_edges_for_call_stmt_node): Likewise. (cgraph_edge::verify_corresponds_to_fndecl): Likewise. (cgraph_node::verify_node): Likewise. * cgraphclones.c (build_function_decl_skip_args): Likewise. (cgraph_node::create_clone): Likewise. * config/arm/arm.c (arm_insert_attributes): Likewise. * config/i386/i386.c (ix86_gimple_fold_builtin): Likewise. * dse.c (scan_insn): Likewise. * expr.c (expand_expr_real_1): Likewise. * fold-const.c (operand_equal_p): Likewise. (fold_binary_loc): Likewise. * gimple-fold.c (gimple_fold_stmt_to_constant_1): Likewise. * gimple-low.c (lower_stmt): Likewise. * gimple-pretty-print.c (dump_gimple_call): Likewise. * gimple-ssa-warn-restrict.c (wrestrict_dom_walker::check_call): Likewise. * gimple.c (gimple_build_call_from_tree): Likewise. (gimple_call_builtin_p): Likewise. (gimple_call_combined_fn): Likewise. * gimplify.c (gimplify_call_expr): Likewise. (gimple_boolify): Likewise. (gimplify_modify_expr): Likewise. (gimplify_addr_expr): Likewise. * hsa-gen.c (gen_hsa_insns_for_call): Likewise. * ipa-cp.c (determine_versionability): Likewise. * ipa-fnsummary.c (compute_fn_summary): Likewise. * ipa-param-manipulation.c (ipa_modify_formal_parameters): Likewise. * ipa-split.c (visit_bb): Likewise. (split_function): Likewise. * ipa-visibility.c (cgraph_externally_visible_p): Likewise. * lto-cgraph.c (input_node): Likewise. * lto-streamer-out.c (write_symbol): Likewise. * omp-low.c (setjmp_or_longjmp_p): Likewise. (lower_omp_1): Likewise. * predict.c (strip_predict_hints): Likewise. * print-tree.c (print_node): Likewise. * symtab.c (symtab_node::output_to_lto_symbol_table_p): Likewise. * trans-mem.c (is_tm_irrevocable): Likewise. (is_tm_load): Likewise. (is_tm_simple_load): Likewise. (is_tm_store): Likewise. (is_tm_simple_store): Likewise. (is_tm_abort): Likewise. (tm_region_init_1): Likewise. * tree-call-cdce.c (gen_shrink_wrap_conditions): Likewise. * tree-cfg.c (verify_gimple_call): Likewise. (move_stmt_r): Likewise. (stmt_can_terminate_bb_p): Likewise. * tree-eh.c (lower_eh_constructs_2): Likewise. * tree-if-conv.c (if_convertible_stmt_p): Likewise. * tree-inline.c (remap_gimple_stmt): Likewise. (copy_bb): Likewise. (estimate_num_insns): Likewise. (fold_marked_statements): Likewise. * tree-sra.c (scan_function): Likewise. * tree-ssa-ccp.c (surely_varying_stmt_p): Likewise. (optimize_stack_restore): Likewise. (pass_fold_builtins::execute): Likewise. * tree-ssa-dce.c (mark_stmt_if_obviously_necessary): Likewise. (mark_all_reaching_defs_necessary_1): Likewise. * tree-ssa-dom.c (dom_opt_dom_walker::optimize_stmt): Likewise. * tree-ssa-forwprop.c (simplify_builtin_call): Likewise. (pass_forwprop::execute): Likewise. * tree-ssa-loop-im.c (stmt_cost): Likewise. * tree-ssa-math-opts.c (pass_cse_reciprocals::execute): Likewise. * tree-ssa-sccvn.c (fully_constant_vn_reference_p): Likewise. * tree-ssa-strlen.c (get_string_length): Likewise. * tree-ssa-structalias.c (handle_lhs_call): Likewise. (find_func_aliases_for_call): Likewise. * tree-ssa-ter.c (find_replaceable_in_bb): Likewise. * tree-stdarg.c (optimize_va_list_gpr_fpr_size): Likewise. * tree-tailcall.c (find_tail_calls): Likewise. * tree.c (need_assembler_name_p): Likewise. (free_lang_data_in_decl): Likewise. (get_call_combined_fn): Likewise. * ubsan.c (is_ubsan_builtin_p): Likewise. * varasm.c (incorporeal_function_p): Likewise. * tree.h (DECL_BUILT_IN): Remove and replace with fndecl_built_in_p. (DECL_BUILT_IN_P): Transfort to fndecl_built_in_p. (fndecl_built_in_p): New. 2018-08-27 Martin Liska <mliska@suse.cz> * gcc-interface/decl.c (update_profile): Use new function fndecl_built_in_p and remove check for FUNCTION_DECL if possible. * gcc-interface/gigi.h (call_is_atomic_load): Likewise. * gcc-interface/utils.c (gnat_pushdecl): Likewise. 2018-08-27 Martin Liska <mliska@suse.cz> * c-common.c (check_function_restrict): Use new function fndecl_built_in_p and remove check for FUNCTION_DECL if possible. (check_builtin_function_arguments): Likewise. (reject_gcc_builtin): Likewise. * c-warn.c (sizeof_pointer_memaccess_warning): Likewise. 2018-08-27 Martin Liska <mliska@suse.cz> * c-decl.c (locate_old_decl): Use new function fndecl_built_in_p and remove check for FUNCTION_DECL if possible. (diagnose_mismatched_decls): Likewise. (merge_decls): Likewise. (warn_if_shadowing): Likewise. (pushdecl): Likewise. (implicitly_declare): Likewise. * c-parser.c (c_parser_postfix_expression_after_primary): Likewise. * c-tree.h (C_DECL_ISNT_PROTOTYPE): Likewise. * c-typeck.c (build_function_call_vec): Likewise. (convert_arguments): Likewise. 2018-08-27 Martin Liska <mliska@suse.cz> * call.c (build_call_a): Use new function fndecl_built_in_p and remove check for FUNCTION_DECL if possible. (build_cxx_call): Likewise. * constexpr.c (constexpr_fn_retval): Likewise. (cxx_eval_builtin_function_call): Likewise. (cxx_eval_call_expression): Likewise. (potential_constant_expression_1): Likewise. * cp-gimplify.c (cp_gimplify_expr): Likewise. (cp_fold): Likewise. * decl.c (decls_match): Likewise. (validate_constexpr_redeclaration): Likewise. (duplicate_decls): Likewise. (make_rtl_for_nonlocal_decl): Likewise. * name-lookup.c (consider_binding_level): Likewise. (cp_emit_debug_info_for_using): Likewise. * semantics.c (finish_call_expr): Likewise. * tree.c (builtin_valid_in_constant_expr_p): Likewise. 2018-08-27 Martin Liska <mliska@suse.cz> * go-gcc.cc (Gcc_backend::call_expression): Use new function fndecl_built_in_p and remove check for FUNCTION_DECL if possible. 2018-08-27 Martin Liska <mliska@suse.cz> * lto-lang.c (handle_const_attribute): Use new function fndecl_built_in_p and remove check for FUNCTION_DECL if possible. * lto-symtab.c (lto_symtab_merge_p): Likewise. (lto_symtab_merge_decls_1): Likewise. (lto_symtab_merge_symbols): Likewise. * lto.c (lto_maybe_register_decl): Likewise. (read_cgraph_and_symbols): Likewise. From-SVN: r263880
2018-08-26PR c++/87029, Implement -Wredundant-move.Marek Polacek2-8/+34
* c.opt (Wredundant-move): New option. * typeck.c (treat_lvalue_as_rvalue_p): New function. (maybe_warn_pessimizing_move): Call convert_from_reference. Warn about redundant moves. * doc/invoke.texi: Document -Wredundant-move. * g++.dg/cpp0x/Wredundant-move1.C: New test. * g++.dg/cpp0x/Wredundant-move2.C: New test. * g++.dg/cpp0x/Wredundant-move3.C: New test. * g++.dg/cpp0x/Wredundant-move4.C: New test. From-SVN: r263863
2018-08-26re PR c++/87080 (ice in cp_get_fndecl_from_callee, at cp/cvt.c:965)Marek Polacek2-0/+10
PR c++/87080 * typeck.c (maybe_warn_pessimizing_move): Do nothing in a template. * g++.dg/cpp0x/Wpessimizing-move5.C: New test. From-SVN: r263862
2018-08-24re PR c++/67012 (decltype(auto) with trailing return type)Marek Polacek2-1/+22
PR c++/67012 PR c++/86942 * decl.c (grokdeclarator): Disallow functions with trailing return type with decltype(auto) as its type. Also check the function if it's inner declarator doesn't exist * g++.dg/cpp0x/auto52.C: New test. * g++.dg/cpp1y/auto-fn52.C: New test. * g++.dg/cpp1y/auto-fn53.C: New test. * g++.dg/cpp1y/auto-fn54.C: New test. From-SVN: r263836
2018-08-21re PR c++/86499 (lambda-expressions with capture-default are allowed at ↵Marek Polacek2-0/+9
namespace scope) PR c++/86499 * parser.c (cp_parser_lambda_introducer): Give error if a non-local lambda has a capture-default. * g++.dg/cpp0x/lambda/lambda-non-local.C: New test. * g++.dg/cpp0x/lambda/lambda-this10.C: Adjust dg-error. From-SVN: r263749
2018-08-21decl.c (check_static_variable_definition): Change to return void.Paolo Carlini2-21/+17
2018-08-21 Paolo Carlini <paolo.carlini@oracle.com> * decl.c (check_static_variable_definition): Change to return void. From-SVN: r263742
2018-08-21PR c++/86981, Implement -Wpessimizing-move.Marek Polacek2-19/+106
* c.opt (Wpessimizing-move): New option. * typeck.c (decl_in_std_namespace_p): New. (is_std_move_p): New. (maybe_warn_pessimizing_move): New. (can_do_nrvo_p): New, factored out of ... (check_return_expr): ... here. Warn about potentially harmful std::move in a return statement. * doc/invoke.texi: Document -Wpessimizing-move. * g++.dg/cpp0x/Wpessimizing-move1.C: New test. * g++.dg/cpp0x/Wpessimizing-move2.C: New test. * g++.dg/cpp0x/Wpessimizing-move3.C: New test. * g++.dg/cpp0x/Wpessimizing-move4.C: New test. * g++.dg/cpp1z/Wpessimizing-move1.C: New test. From-SVN: r263741
2018-08-21re PR c++/65043 (Expected narrowing conversion during list initialization of ↵Marek Polacek3-1/+8
bool from double) PR c++/65043 * call.c (standard_conversion): Set check_narrowing. * typeck2.c (check_narrowing): Use CP_INTEGRAL_TYPE_P rather than comparing with INTEGER_TYPE. * g++.dg/concepts/pr67595.C: Add dg-warning. * g++.dg/cpp0x/Wnarrowing11.C: New test. * g++.dg/cpp0x/Wnarrowing12.C: New test. * g++.dg/cpp0x/rv-cast5.C: Add static_cast. From-SVN: r263739
2018-08-21* cp-tree.h: Fix typo.Marek Polacek2-1/+5
From-SVN: r263738
2018-08-20Add support for grouping of related diagnostics (PR other/84889)David Malcolm19-101/+310
We often emit logically-related groups of diagnostics. A relatively simple case is this: if (warning_at (body_loc, OPT_Wmultistatement_macros, "macro expands to multiple statements")) inform (guard_loc, "some parts of macro expansion are not guarded by " "this %qs clause", guard_tinfo_to_string (keyword)); where the "note" diagnostic issued by the "inform" call is guarded by the -Wmultistatement_macros warning. More complicated examples can be seen in the C++ frontend, where e.g. print_z_candidates can lead to numerous "note" diagnostics being emitted. I'm looking at various ways to improve how we handle such related diagnostics, but, prior to this patch, there was no explicit relationship between these diagnostics: the diagnostics subsystem had no way of "knowing" that these were related. This patch introduces a simple way to group the diagnostics: an auto_diagnostic_group class: all diagnostics emitted within the lifetime of an auto_diagnostic_group instance are logically grouped. Hence in the above example, the two diagnostics can be grouped by simply adding an auto_diagnostic_group instance: auto_diagnostic_group d; if (warning_at (body_loc, OPT_Wmultistatement_macros, "macro expands to multiple statements")) inform (guard_loc, "some parts of macro expansion are not guarded by " "this %qs clause", guard_tinfo_to_string (keyword)); Some more awkard cases are of the form: if (some_condition && warning_at (...) && more_conditions) inform (...); which thus need restructuring to: if (some_condition) { auto_diagnostic_group d; warning_at (...); if (more_conditions) inform (...); } so that the lifetime of the auto_diagnostic_group groups the warning_at and the inform call. Nesting is handled by simply tracking a nesting depth within the diagnostic_context.: all diagnostics are treated as grouped until the final auto_diagnostic_group is popped. diagnostic.c uses this internally, so that all diagnostics are part of a group - those that are "by themselves" are treated as being part of a group with one element. The diagnostic_context gains optional callbacks for displaying the start of a group (when the first diagnostic is emitted within it), and the end of a group (for when the group was non-empty); these callbacks are unused by default, but a test plugin demonstrates them (and verifies that the machinery is working). As noted above, I'm looking at various ways to use the grouping to improve how we output the diagnostics. FWIW, I experimented with a more involved implementation, of the form: diagnostic_group d; if (d.warning_at (body_loc, OPT_Wmultistatement_macros, "macro expands to multiple statements")) d.inform (guard_loc, "some parts of macro expansion are not guarded by " "this %qs clause", guard_tinfo_to_string (keyword)); which had the advantage of allowing auto-detection of the places where groups were needed (by converting ::warning_at's return type to bool), but it was a much more invasive patch, especially when dealing with the places in the C++ frontend that can emit numerous notes after an error or warning (and thus having to pass the group around) Hence I went with this simpler approach. gcc/c-family/ChangeLog: PR other/84889 * c-attribs.c (common_handle_aligned_attribute): Add auto_diagnostic_group instance. * c-indentation.c (warn_for_misleading_indentation): Likewise. * c-opts.c (c_common_post_options): Likewise. * c-warn.c (warn_logical_not_parentheses): Likewise. (warn_duplicated_cond_add_or_warn): Likewise. (warn_for_multistatement_macros): Likewise. gcc/c/ChangeLog: PR other/84889 * c-decl.c (pushtag): Add auto_diagnostic_group instance. (diagnose_mismatched_decls): Likewise, in various places. (warn_if_shadowing): Likewise. (implicit_decl_warning): Likewise. (implicitly_declare): Likewise. (undeclared_variable): Likewise. (declare_label): Likewise. (grokdeclarator): Likewise. (start_function): Likewise. * c-parser.c (c_parser_declaration_or_fndef): Likewise. (c_parser_parameter_declaration): Likewise. (c_parser_binary_expression): Likewise. * c-typeck.c (c_expr_sizeof_expr): Likewise. (parser_build_binary_op): Likewise. (build_unary_op): Likewise. (error_init): Likewise. (pedwarn_init): Likewise. (warning_init): Likewise. (convert_for_assignment): Likewise. gcc/cp/ChangeLog: PR other/84889 * call.c (build_user_type_conversion_1): Add auto_diagnostic_group instance(s). (print_error_for_call_failure): Likewise. (build_op_call_1): Likewise. (build_conditional_expr_1): Likewise. (build_new_op_1): Likewise. (build_op_delete_call): Likewise. (convert_like_real): Likewise. (build_over_call): Likewise. (build_new_method_call_1): Likewise. (joust): Likewise. * class.c (check_tag): Likewise. (finish_struct_anon_r): Likewise. (one_inherited_ctor): Likewise. (finalize_literal_type_property): Likewise. (explain_non_literal_class): Likewise. (find_flexarrays): Likewise. (resolve_address_of_overloaded_function): Likewise. * constexpr.c (ensure_literal_type_for_constexpr_object): Likewise. (is_valid_constexpr_fn): Likewise. (cx_check_missing_mem_inits): Likewise. * cp-gimplify.c (cp_genericize_r): Likewise. * cvt.c (maybe_warn_nodiscard): Likewise. * decl.c (warn_extern_redeclared_static): Likewise. (check_redeclaration_exception_specification): Likewise. (check_no_redeclaration_friend_default_args): Likewise. (duplicate_decls): Likewise. (redeclaration_error_message): Likewise. (warn_misplaced_attr_for_class_type): Likewise. * decl2.c (finish_static_data_member_decl): Likewise. (no_linkage_error): Likewise. (cp_warn_deprecated_use): Likewise. * error.c (qualified_name_lookup_error): Likewise. * friend.c (make_friend_class): Likewise. (do_friend): Likewise. * init.c (perform_member_init): Likewise. (build_new_1): Likewise. (build_vec_delete_1): Likewise. (build_delete): Likewise. * lex.c (unqualified_name_lookup_error): Likewise. * name-lookup.c (check_extern_c_conflict): Likewise. (inform_shadowed): New function. (check_local_shadow): Add auto_diagnostic_group instances, replacing goto "inform_shadowed" label with call to subroutine. (set_local_extern_decl_linkage): Add auto_diagnostic_group instance(s). * parser.c (cp_parser_diagnose_invalid_type_name): Likewise. (cp_parser_namespace_name): Likewise. * pt.c (check_specialization_namespace): Likewise. (check_template_variable): Likewise. (warn_spec_missing_attributes): Likewise. (check_explicit_specialization): Likewise. (process_partial_specialization): Likewise. (lookup_template_class_1): Likewise. (finish_template_variable): Likewise. (do_auto_deduction): Likewise. * search.c (check_final_overrider): Likewise. (look_for_overrides_r): Likewise. * tree.c (maybe_warn_parm_abi): Likewise. * typeck.c (cxx_sizeof_expr): Likewise. (cp_build_function_call_vec): Likewise. (cp_build_binary_op): Likewise. (convert_for_assignment): Likewise. (maybe_warn_about_returning_address_of_local): Likewise. * typeck2.c (abstract_virtuals_error_sfinae): Likewise. (check_narrowing): Likewise. gcc/ChangeLog: PR other/84889 * attribs.c (diag_attr_exclusions): Add auto_diagnostic_group instance. (decl_attributes): Likewise. * calls.c (maybe_warn_nonstring_arg): Add auto_diagnostic_group instance. * cgraphunit.c (maybe_diag_incompatible_alias): Likewise. * diagnostic-core.h (class auto_diagnostic_group): New class. * diagnostic.c (diagnostic_initialize): Initialize the new fields. (diagnostic_report_diagnostic): Handle the first diagnostics within a group. (emit_diagnostic): Add auto_diagnostic_group instance. (inform): Likewise. (inform_n): Likewise. (warning): Likewise. (warning_at): Likewise. (warning_n): Likewise. (pedwarn): Likewise. (permerror): Likewise. (error): Likewise. (error_n): Likewise. (error_at): Likewise. (sorry): Likewise. (fatal_error): Likewise. (internal_error): Likewise. (internal_error_no_backtrace): Likewise. (auto_diagnostic_group::auto_diagnostic_group): New ctor. (auto_diagnostic_group::~auto_diagnostic_group): New dtor. * diagnostic.h (struct diagnostic_context): Add fields "diagnostic_group_nesting_depth", "diagnostic_group_emission_count", "begin_group_cb", "end_group_cb". * gimple-ssa-isolate-paths.c (find_implicit_erroneous_behavior): Add auto_diagnostic_group instance(s). (find_explicit_erroneous_behavior): Likewise. * gimple-ssa-warn-alloca.c (pass_walloca::execute): Likewise. * gimple-ssa-warn-restrict.c (maybe_diag_offset_bounds): Likewise. * gimplify.c (warn_implicit_fallthrough_r): Likewise. (gimplify_va_arg_expr): Likewise. * hsa-gen.c (HSA_SORRY_ATV): Likewise. (HSA_SORRY_AT): Likewise. * ipa-devirt.c (compare_virtual_tables): Likewise. (warn_odr): Likewise. * multiple_target.c (expand_target_clones): Likewise. * opts-common.c (cmdline_handle_error): Likewise. * reginfo.c (globalize_reg): Likewise. * substring-locations.c (format_warning_n_va): Likewise. * tree-inline.c (expand_call_inline): Likewise. * tree-ssa-ccp.c (pass_post_ipa_warn::execute): Likewise. * tree-ssa-loop-niter.c (do_warn_aggressive_loop_optimizations): Likewise. * tree-ssa-uninit.c (warn_uninit): Likewise. * tree.c (warn_deprecated_use): Likewise. gcc/testsuite/ChangeLog: PR other/84889 * gcc.dg/plugin/diagnostic-group-test-1.c: New test. * gcc.dg/plugin/diagnostic_group_plugin.c: New test. * gcc.dg/plugin/plugin.exp (plugin_test_list): Add the new tests. From-SVN: r263675
2018-08-17C++: -Wwrite-strings: use location of string constantDavid Malcolm2-4/+11
Consider: extern int callee (const char *one, char *two, const char *three); int test () { return callee ("first", "second", "third"); } for which -Wwrite-strings was emitting: Wwrite-strings.C: In function 'int test()': Wwrite-strings.C:10:44: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings] 10 | return callee ("first", "second", "third"); | ^ This patch fixes the warning so that it underlines the pertinent argument at the callsite: Wwrite-strings.C: In function 'int test()': Wwrite-strings.C:10:27: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings] 10 | return callee ("first", "second", "third"); | ^~~~~~~~ Ideally we ought to also issue a "note" highlighting the pertinent parameter within the decl, but that's not readily available, so I'm saving it for another patch. gcc/cp/ChangeLog: * typeck.c (string_conv_p): Extract location from EXP and use it in preference to input_location when issuing warnings. gcc/testsuite/ChangeLog: * g++.dg/conversion/Wwrite-strings.C: New test. From-SVN: r263635
2018-08-16[PATCH] CPP Macro predicatesNathan Sidwell1-4/+4
https://gcc.gnu.org/ml/gcc-patches/2018-08/msg00897.html libcpp/ * include/cpplib.h (cpp_user_macro_p, cpp_builtin_macro_p) (cpp_macro_p): New inlines. * directives.c (do_pragma_poison): Use cpp_macro_p. (do_ifdef, do_ifndef): Likewise. Use _cpp_maybe_notify_macro_use. (cpp_pop_definition): Use cpp_macro_p. Move _cpp_free_definition earlier. Don't zap node directly. * expr.c (parse_defined): Use _cpp_maybe_notify_macro_use & cpp_macro_p. * files.c (should_stack_file): Use cpp_macro_p. * identifiers.c (cpp_defined): Likewise. * internal.h (_cpp_mark_macro): Use cpp_user_macro_p. (_cpp_notify_macro_use): Declare. (_cpp_maybe_notify_macro_use): New inline. * lex.c (is_macro): Use cpp_macro_p. * macro.c (_cpp_warn_if_unused_macro): Use cpp_user_macro_p. (enter_macro_context): Likewise. (_cpp_create_definition): Use cpp_builtin_macro_p, cpp_user_macro_p. Move _cpp_free_definition earlier. (_cpp_notify_macro_use): New, broken out of multiple call sites. * traditional.c (fun_like_macro_p): Use cpp_builtin_macro_p. (maybe_start_funlike, _cpp_scan_out_logical_line) (push_replacement_text): Likewise. gcc/c-family/ * c-ada-spec.c (count_ada_macro): Use cpp_user_macro_p. (store_ada_macro): Likewise. * c-ppoutput.c (cb_used_define, dump_macro): Likewise. * c-spellcheck.cc (should-suggest_as_macro_p): Likewise, gcc/ * config/rs6000/rs6000-c.c (rs6000_macro_to_expend): Use cpp_macro_p. * config/powerpcspc/powerpcspe-c.c (rs6000_macro_to_expend): Likewise. gcc/cp/ * name-lookup.c (lookup_name_fuzzy): Likewise. gcc/fortran/ * cpp.c (dump_macro): Use cpp_user_macro_p. From-SVN: r263587
2018-08-15diagnostics: add labeling of source rangesDavid Malcolm4-5/+64
This patch adds the ability to label source ranges within a rich_location, to be printed by diagnostic_show_locus. For example: pr69554-1.c:11:18: error: invalid operands to binary + (have 'const char *' and 'const char *') 11 | return (p + 1) + (q + 1); | ~~~~~~~ ^ ~~~~~~~ | | | | | const char * | const char * The patch implements labels for various type mismatch errors in the C and C++ frontends, and in -Wformat. I implemented it wherever accurate location information was guaranteed (there are other places that could benefit, but we need better location information in those places). The labels can be disabled via -fno-diagnostics-show-labels. Similarly: param-type-mismatch.C: In function 'int test_1(int, int, float)': param-type-mismatch.C:11:27: error: invalid conversion from 'int' to 'const char*' [-fpermissive] 11 | return callee_1 (first, second, third); | ^~~~~~ | | | int param-type-mismatch.C:7:43: note: initializing argument 2 of 'int callee_1(int, const char*, float)' 7 | extern int callee_1 (int one, const char *two, float three); | ~~~~~~~~~~~~^~~ where the first "error" describing the bad argument gets a label describing the type inline (since it's non-obvious from "second"). The "note" describing the type of the param of the callee *doesn't* get a label, since that information is explicit there in the source ("const char *two"). The idea is that in any diagnostic where two aspects of the source aren't in sync it ought to be easier for the user if we directly show them the mismatching aspects inline (e.g. types). As well as type mismatch errors, perhaps labels could also be used for buffer overflow warnings, for describing the capacity of the destination buffer vs the size of what's being written: sprintf (buf, "filename: %s\n", file); ^~~ ~~~~~~~~~~~^~~ | | capacity: 32 10 + strlen(file) + 2 or somesuch. Another idea might be for macro expansion warnings: warning: repeated side effects in macro expansion... x = MIN (p++, q++); ~~~~^~~~~~~~~~ note: ...expanded here as #define MIN(X,Y) (X<Y?X:Y) ^~~ ~ ~ ~ ~ ~ ~ | | | | | | | | | | | q++ | | | | p++ | | | q++ | q++ p++ p++ The patch removes some logic from multiline.exp which special-cased lines ending with a '|' character (thus complicating testing of this patch). I believe that this was a vestige from experiments I did to support strippng dg directives from the output; it was present in the earliest version of multiline.exp I posted: "[RFC, stage1] Richer source location information for gcc 6 (location ranges etc)" https://gcc.gnu.org/ml/gcc-patches/2015-03/msg00837.html and I believe was neved used. gcc/c-family/ChangeLog: * c-format.c: Include "selftest-diagnostic.h" and "gcc-rich-location.h". (format_warning_at_char): Pass NULL for new label params of format_warning_va. (class indirection_suffix): New class. (class range_label_for_format_type_mismatch): New class. (format_type_warning): Move logic for generating "*" suffix to class indirection_suffix. Create "fmt_label" and "param_label" to show their types, and pass them to the format_warning_at_substring calls. (selftest::test_type_mismatch_range_labels): New test. (selftest::c_format_c_tests): Call it. gcc/c/ChangeLog: * c-objc-common.c: Include "gcc-rich-location.h". (c_tree_printer): Move implemenation of '%T' to... (print_type): ...this new function. (range_label_for_type_mismatch::get_text): New function. * c-typeck.c (convert_for_assignment): Add type labels to the rhs range for the various ic_argpass cases. (class maybe_range_label_for_tree_type_mismatch): New class. (build_binary_op): Use it when calling binary_op_error. gcc/cp/ChangeLog: * call.c: Include "gcc-rich-location.h". (convert_like_real): Add range label for "invalid conversion" diagnostic. (perform_implicit_conversion_flags): Add type label to the "could not convert" error. * error.c: Include "gcc-rich-location.h". (range_label_for_type_mismatch::get_text): New function. * typeck.c (convert_for_assignment): Add type label to the "cannot convert" error if a location is available. gcc/ChangeLog: * common.opt (fdiagnostics-show-labels): New option. * diagnostic-show-locus.c (class layout_range): Add field "m_label". (class layout): Add field "m_show_labels_p". (layout_range::layout_range): Add param "label" and use it to initialize m_label. (make_range): Pass in NULL for new "label" param of layout_range's ctor. (layout::layout): Initialize m_show_labels_p. (layout::maybe_add_location_range): Pass in loc_range->m_label when constructing layout_range instances. (struct line_label): New struct. (layout::print_any_labels): New member function. (layout::print_line): Call it if label-printing is enabled. (selftest::test_one_liner_labels): New test. (selftest::test_diagnostic_show_locus_one_liner): Call it. * diagnostic.c (diagnostic_initialize): Initialize context->show_labels_p. * diagnostic.h (struct diagnostic_context): Add field "show_labels_p". * doc/invoke.texi (Diagnostic Message Formatting Options): Add -fno-diagnostics-show-labels. * dwarf2out.c (gen_producer_string): Add OPT_fdiagnostics_show_labels to the ignored options. * gcc-rich-location.c (gcc_rich_location::add_expr): Add "label" param. (gcc_rich_location::maybe_add_expr): Likewise. * gcc-rich-location.h (gcc_rich_location::gcc_rich_location): Add label" param, defaulting to NULL. (gcc_rich_location::add_expr): Add "label" param. (gcc_rich_location::maybe_add_expr): Likewise. (class text_range_label): New class. (class range_label_for_type_mismatch): New class. * gimple-ssa-sprintf.c (fmtwarn): Pass NULL for new label params of format_warning_va. (fmtwarn_n): Likewise for new params of format_warning_n_va. * lto-wrapper.c (merge_and_complain): Add OPT_fdiagnostics_show_labels to the "pick one setting" options. (append_compiler_options): Likewise to the dropped options. (append_diag_options): Likewise to the passed-on options. * opts.c (common_handle_option): Handle the new option. * selftest-diagnostic.c (test_diagnostic_context::test_diagnostic_context): Enable show_labels_p. * substring-locations.c: Include "gcc-rich-location.h". (format_warning_n_va): Add "fmt_label" and "param_label" params and use them as appropriate. (format_warning_va): Add "fmt_label" and "param_label" params, passing them on to format_warning_n_va. (format_warning_at_substring): Likewise. (format_warning_at_substring_n): Likewise. * substring-locations.h (format_warning_va): Add "fmt_label" and "param_label" params. (format_warning_n_va): Likewise. (format_warning_at_substring): Likewise. (format_warning_at_substring_n): Likewise. * toplev.c (general_init): Initialize global_dc->show_labels_p. gcc/testsuite/ChangeLog: * g++.dg/diagnostic/aka3.C: New test. * g++.dg/diagnostic/param-type-mismatch-2.C: Update expected output to show range labels. * g++.dg/diagnostic/param-type-mismatch.C: Likewise. * g++.dg/plugin/plugin.exp (plugin_test_list): Add... * g++.dg/plugin/show-template-tree-color-labels.C: New test. * gcc.dg/bad-binary-ops.c: Update expected output to show range labels. Add an "aka" example. * gcc.dg/cpp/pr66415-1.c: Update expected output to show range labels. * gcc.dg/format/diagnostic-ranges.c: Likewise. * gcc.dg/format/pr72858.c: Likewise. * gcc.dg/format/pr78498.c: Likewise. * gcc.dg/param-type-mismatch.c: Add "-Wpointer-sign" to options. Update expected output to show range labels. Add examples of -Wincompatible-pointer-types and -Wpointer-sign for parameters. * gcc.dg/plugin/diagnostic-test-show-locus-bw-line-numbers.c: Update expected output to show range labels. * gcc.dg/plugin/diagnostic-test-show-locus-bw.c: Likewise. (test_very_wide_line): Adjust so that label is at left-clipping boundary. (test_very_wide_line_2): New test. * gcc.dg/plugin/diagnostic-test-show-locus-color-line-numbers.c: Update expected output to show range labels. * gcc.dg/plugin/diagnostic-test-show-locus-color.c: Likewise. * gcc.dg/plugin/diagnostic-test-show-locus-no-labels.c: New test. * gcc.dg/plugin/diagnostic_plugin_show_trees.c (show_tree): Update for new param to gcc_rich_location::add_expr. * gcc.dg/plugin/diagnostic_plugin_test_show_locus.c (add_range): Add "label" param. (test_show_locus): Add examples of labels to various tests. Tweak the "very wide_line" test case and duplicate it, to cover the boundary values for clipping of labels against the left-margin. * gcc.dg/plugin/plugin.exp (plugin_test_list): Add diagnostic-test-show-locus-no-labels.c. * gcc.dg/pr69554-1.c: Update expected output to show range labels. Update line numbers of dg-locus directives. * gcc.dg/pr69627.c: Update expected output to show range labels. * lib/multiline.exp (proc _build_multiline_regex): Remove special-case handling of lines with trailing '|'. libcpp/ChangeLog: * include/line-map.h (struct location_range): Add "m_label" field. (class rich_location): Add description of labels to leading comment. (rich_location::rich_location): Add "label" param, defaulting to NULL. (rich_location::add_range): Likewise. (struct label_text): New struct. (class range_label): New abstract base class. * line-map.c (rich_location::rich_location): Add "label" param; use it. (rich_location::add_range): Likewise. From-SVN: r263564
2018-08-15decl.c (check_previous_goto_1): When decl_jump_unsafe returns 2 emit an ↵Paolo Carlini2-1/+7
error instead of a permerror. /cp 2018-08-15 Paolo Carlini <paolo.carlini@oracle.com> * decl.c (check_previous_goto_1): When decl_jump_unsafe returns 2 emit an error instead of a permerror. /testsuite 2018-08-15 Paolo Carlini <paolo.carlini@oracle.com> * g++.dg/init/goto3.C: Adjust for error instead of permerror. From-SVN: r263551
2018-08-13re PR c++/57891 (No diagnostic of narrowing conversion in non-type template ↵Marek Polacek6-15/+54
argument) PR c++/57891 * call.c (struct conversion): Add check_narrowing_const_only. (build_converted_constant_expr): Set check_narrowing and check_narrowing_const_only. Give error if expr is error node. (convert_like_real): Pass it to check_narrowing. * cp-tree.h (check_narrowing): Add a default parameter. * decl.c (compute_array_index_type): Use input_location instead of location_of. * pt.c (convert_nontype_argument): Return NULL_TREE if tf_error. * typeck2.c (check_narrowing): Don't warn for instantiation-dependent expressions. Call maybe_constant_value instead of fold_non_dependent_expr. Don't mention { } in diagnostic. Only check narrowing for constants if CONST_ONLY. * g++.dg/cpp0x/Wnarrowing6.C: New test. * g++.dg/cpp0x/Wnarrowing7.C: New test. * g++.dg/cpp0x/Wnarrowing8.C: New test. * g++.dg/cpp0x/Wnarrowing9.C: New test. * g++.dg/cpp0x/Wnarrowing10.C: New test. * g++.dg/cpp0x/constexpr-47969.C: Adjust dg-error. * g++.dg/cpp0x/constexpr-ex2.C: Likewise. * g++.dg/cpp0x/constexpr-targ.C: Likewise. * g++.dg/cpp0x/scoped_enum2.C: Likewise. * g++.dg/ext/stmtexpr15.C: Likewise. * g++.dg/gomp/pr47963.C: Likewise. * g++.dg/init/new37.C: Likewise. * g++.dg/init/new43.C: Likewise. * g++.dg/other/fold1.C: Likewise. * g++.dg/parse/array-size2.C: Likewise. * g++.dg/template/dependent-name3.C: Likewise. * g++.dg/cpp0x/constexpr-data2.C: Add dg-error. * g++.dg/other/vrp1.C: Likewise. * g++.dg/template/char1.C: Likewise. From-SVN: r263523
2018-08-13PR tree-optimization/71625 - missing strlen optimization on different array ↵Martin Sebor3-2/+46
initialization style gcc/c/ChangeLog: PR tree-optimization/71625 * c-parser.c (c_parser_declaration_or_fndef): Call braced_list_to_string. gcc/c-family/ChangeLog: PR tree-optimization/71625 * c-common.c (braced_list_to_string): New function. * c-common.h (braced_list_to_string): Declare it. gcc/cp/ChangeLog: PR tree-optimization/71625 * decl.c (check_initializer): Call braced_list_to_string. (eval_check_narrowing): New function. * gcc/cp/typeck2.c (digest_init_r): Accept strings literals as initilizers for all narrow character types. gcc/testsuite/ChangeLog: PR tree-optimization/71625 * g++.dg/init/string2.C: New test. * g++.dg/init/string3.C: New test. * g++.dg/init/string4.C: New test. * gcc.dg/init-string-3.c: New test. * gcc.dg/strlenopt-55.c: New test. * gcc.dg/strlenopt-56.c: New test. From-SVN: r263511
2018-08-13P0806R2 - Deprecate implicit capture of this via [=]Marek Polacek2-5/+18
P0806R2 - Deprecate implicit capture of this via [=] * lambda.c (add_default_capture): Formatting fixes. Warn about deprecated implicit capture of this via [=]. * g++.dg/cpp2a/lambda-this1.C: New test. * g++.dg/cpp2a/lambda-this2.C: New test. * g++.dg/cpp2a/lambda-this3.C: New test. From-SVN: r263508
2018-08-13re PR c++/86915 (Segmentation fault for an array of auto in template parameter)Marek Polacek2-1/+9
PR c++/86915 * decl.c (create_array_type_for_decl): Handle null name. * g++.dg/diagnostic/auto1.C: New test. From-SVN: r263507
2018-08-11PR c++/86728 - C variadic generic lambda.Jason Merrill2-1/+8
* parser.c (cp_parser_parameter_declaration): Don't turn 'auto' into a pack if it's followed by a declarator-id. From-SVN: r263484
2018-08-08P0595R1 - is_constant_evaluatedJakub Jelinek8-19/+137
P0595R1 - is_constant_evaluated cp/ * cp-tree.h (enum cp_built_in_function): New. (maybe_constant_init): Add pretend_const_required argument. * typeck2.c (store_init_value): Pass true as new argument to maybe_constant_init. * constexpr.c (constexpr_fn_retval): Check also DECL_BUILT_IN_CLASS for BUILT_IN_UNREACHABLE. (struct constexpr_ctx): Add pretend_const_required field. (cxx_eval_builtin_function_call): Use DECL_IS_BUILTIN_CONSTANT_P macro. Handle CP_BUILT_IN_IS_CONSTANT_EVALUATED. Check also DECL_BUILT_IN_CLASS for BUILT_IN_UNREACHABLE. (cxx_eval_outermost_constant_expr): Add pretend_const_required argument, initialize pretend_const_required field in ctx. If the result is TREE_CONSTANT and non_constant_p, retry with pretend_const_required false if it was true. (is_sub_constant_expr): Initialize pretend_const_required_field in ctx. (cxx_constant_value): Pass true as pretend_const_required to cxx_eval_outermost_constant_expr. (maybe_constant_value): Pass false as pretend_const_required to cxx_eval_outermost_constant_expr. (fold_non_dependent_expr): Likewise. (maybe_constant_init_1): Add pretend_const_required argument, pass it down to cxx_eval_outermost_constant_expr. Pass !allow_non_constant instead of false as strict to cxx_eval_outermost_constant_expr. (maybe_constant_init): Add pretend_const_required argument, pass it down to maybe_constant_init_1. (cxx_constant_init): Pass true as pretend_const_required to maybe_constant_init_1. * cp-gimplify.c (cp_gimplify_expr): Handle CALL_EXPRs to CP_BUILT_IN_IS_CONSTANT_EVALUATED. (cp_fold): Don't fold CP_BUILT_IN_IS_CONSTANT_EVALUATED calls. * decl.c: Include langhooks.h. (cxx_init_decl_processing): Register __builtin_is_constant_evaluated built-in. * tree.c (builtin_valid_in_constant_expr_p): Return true for CP_BUILT_IN_IS_CONSTANT_EVALUATED. * pt.c (declare_integer_pack): Initialize DECL_FUNCTION_CODE. testsuite/ * g++.dg/cpp2a/is-constant-evaluated1.C: New test. From-SVN: r263392
2018-08-08re PR c++/86836 (internal compiler error on structured bindings with shadow ↵Jakub Jelinek2-17/+22
parameter on templated function) PR c++/86836 * pt.c (tsubst_expr): For structured bindings, call tsubst_decomp_names before tsubst_init, not after it. * g++.dg/cpp1z/decomp46.C: New test. From-SVN: r263391
2018-08-08re PR c++/86738 (gcc 8.2: Internal compiler error memcpy)Jakub Jelinek2-3/+16
PR c++/86738 * constexpr.c (cxx_eval_binary_expression): For arithmetics involving NULL pointer set *non_constant_p to true. (cxx_eval_component_reference): For dereferencing of a NULL pointer, set *non_constant_p to true and return t. * g++.dg/opt/pr86738.C: New test. From-SVN: r263390
2018-08-07PR c++/59480, DR 136Paolo Carlini2-7/+76
/cp 2018-08-07 Paolo Carlini <paolo.carlini@oracle.com> PR c++/59480, DR 136 * decl.c (check_no_redeclaration_friend_default_args): New. (duplicate_decls): Use the latter; also check that a friend declaration specifying default arguments is a definition. /testsuite 2018-08-07 Paolo Carlini <paolo.carlini@oracle.com> PR c++/59480, DR 136 * g++.dg/other/friend8.C: New. * g++.dg/other/friend9.C: Likewise. * g++.dg/other/friend10.C: Likewise. * g++.dg/other/friend11.C: Likewise. * g++.dg/other/friend12.C: Likewise. * g++.dg/other/friend13.C: Likewise. * g++.dg/other/friend14.C: Likewise. * g++.dg/other/friend15.C: Likewise. * g++.dg/parse/defarg4.C: Compile with -fpermissive -w. * g++.dg/parse/defarg8.C: Likewise. From-SVN: r263361
2018-08-07re PR c++/79133 (lambda capture shadowing parameter & decltype confusion)Ville Voutilainen2-1/+23
PR c++/79133 gcc/cp/ PR c++/79133 * name-lookup.c (check_local_shadow): Reject captures and parameters with the same name. testsuite/ PR c++/79133 * g++.dg/cpp0x/lambda/lambda-shadow3.C: New. * g++.dg/cpp1y/lambda-generic-variadic18.C: Likewise. From-SVN: r263357
2018-08-06re PR c++/86767 (continue statements in constexpr functions causes unbounded ↵Marek Polacek2-0/+15
looping) PR c++/86767 * constexpr.c (cxx_eval_statement_list): Handle continue. * g++.dg/cpp1y/constexpr-86767.C: New test. From-SVN: r263340
2018-08-03Add fix-it hint for missing return statement in assignment operators (PR ↵David Malcolm2-2/+40
c++/85523) gcc/cp/ChangeLog: PR c++/85523 * decl.c: Include "gcc-rich-location.h". (add_return_star_this_fixit): New function. (finish_function): When warning about missing return statements in functions returning non-void, add a "return *this;" fix-it hint for assignment operators. gcc/testsuite/ChangeLog: PR c++/85523 * g++.dg/pr85523.C: New test. Co-Authored-By: Jonathan Wakely <jwakely@redhat.com> From-SVN: r263298