summaryrefslogtreecommitdiff
path: root/gcc/cp/constexpr.c
Commit message (Collapse)AuthorAgeFilesLines
* re PR c++/77830 (internal compiler error: in ↵Jakub Jelinek2016-12-211-35/+82
| | | | | | | | | | | | | | | | output_constructor_regular_field, at varasm.c:4968, when using constexpr (with testcase)) PR c++/77830 * constexpr.c (cxx_eval_array_reference): Perform out of bounds verification even if lval is true, just allow one past the last element in that case. (cxx_eval_store_expression): Detect stores to out of bound ARRAY_REF. * g++.dg/cpp1y/pr77830.C: New test. * g++.dg/cpp0x/pr65398.C: Adjust expected diagnostics. From-SVN: r243873
* re PR c++/78551 (Internal compiler error with constexpr initialization of union)Nathan Sidwell2016-12-081-9/+52
| | | | | | | | | | | | | PR c++/78551 * constexpr.c (extract_string_elt): New. Broken out of ... (cxx_eval_array_reference): ... here. Call it. (cxx_eval_store_expression): Convert init by STRING_CST into CONSTRUCTOR, if needed. PR c++/78551 * g++.dg/cpp1y/pr78551.C: New. From-SVN: r243448
* PR c++/77907 - static init and PMFJason Merrill2016-11-271-1/+1
| | | | | | * constexpr.c (cxx_eval_constant_expression): Use cp_fold_convert. From-SVN: r242906
* Allow references in constant-expressions.Jason Merrill2016-11-151-0/+4
| | | | | | | | | | * decl2.c (decl_maybe_constant_var_p): References qualify. * constexpr.c (non_const_var_error): Handle references. * init.c (constant_value_1): Always check decl_constant_var_p. * cp-gimplify.c (cp_fold_maybe_rvalue): Don't fold references. * error.c (dump_decl_name): Split out from dump_decl. From-SVN: r242422
* Implement P0217R3 - C++17 structured bindingsJakub Jelinek2016-11-141-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | gcc/ * match.pd: Don't try to compare addresses of variables with DECL_VALUE_EXPR. gcc/cp/ * cp-tree.h (struct lang_decl_base): Add decomposition_p. (DECL_DECOMPOSITION_P): New (enum auto_deduction_context): Add adc_decomp_type. (enum cp_declarator_kind): Add cdk_decomp. * constexpr.c (cxx_eval_constant_expression): Look through DECL_VALUE_EXPR. (potential_constant_expression_1): Likewise. * decl.c (reshape_init): Preserve CONSTRUCTOR_IS_DIRECT_INIT. (check_initializer): Use build_aggr_init for DECL_DECOMPOSITION_P. (cp_finish_decl): Pass adc_decomp_type for decomposition. (find_decomp_class_base, get_tuple_size, get_tuple_element_type) (get_tuple_decomp_init, cp_finish_decomp): New. (grokdeclarator): Handle decomposition. * init.c (build_aggr_init): Handle decomposition array. (build_vec_init): Handle initialization from { array }. * name-lookup.c (add_function): Always wrap TEMPLATE_DECL in OVERLOAD. * parser.c (declarator_can_be_parameter_pack): Handle cdk_decomp. (function_declarator_p, strip_declarator_types) (cp_parser_check_declarator_template_parameters): Likewise. (cp_parser_range_for, cp_convert_range_for): Handle decomposition. (cp_parser_simple_declaration): Parse decomposition. (cp_parser_decomposition_declaration): New. * pt.c (tsubst_decomp_names): New. (subst_expr) [DECL_EXPR, RANGE_FOR_STMT]: Handle decomposition. (do_auto_deduction): Handle adc_decomp_type. * semantics.c (finish_decltype_type): Look through DECL_VALUE_EXPR. * typeck.c (is_bitfield_expr_with_lowered_type): Likewise. * tree.c (lvalue_kind): Likewise. (cp_build_reference_type): Handle reference collapsing. Co-Authored-By: Jason Merrill <jason@redhat.com> From-SVN: r242377
* Fix constexpr lvalue use of __real and __imag.Jason Merrill2016-11-131-2/+2
| | | | | | | * constexpr.c (potential_constant_expression_1): REALPART_EXPR and IMAGPART_EXPR can be lvalues. From-SVN: r242349
* PR c++/77337 - auto return and lambdaJason Merrill2016-11-101-0/+3
| | | | | | | | | | | | | * pt.c (tsubst_friend_function): Don't set DECL_INITIAL. (instantiate_decl): It's OK to defer a constexpr function. * cp-tree.h (DECL_FRIEND_PSEUDO_TEMPLATE_INSTANTIATION): Check DECL_LANG_SPECIFIC. * decl2.c (decl_defined_p): Use it. No longer static. * decl.c (redeclaration_error_message): Use decl_defined_p. * constexpr.c (cxx_eval_call_expression): Set input_location around call to instantiate_decl. From-SVN: r242056
* Implement P0136R1, Rewording inheriting constructors.Jason Merrill2016-11-011-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | gcc/c-family/ * c.opt (-fnew-inheriting-ctors): New. * c-opts.c: Default to on for ABI 11+. gcc/cp/ * call.c (enum rejection_reason_code): Add rr_inherited_ctor. (inherited_ctor_rejection): New. (add_function_candidate): Reject inherited ctors for copying. (enforce_access): Use strip_inheriting_ctors. (print_z_candidate): Likewise. Handle rr_inherited_ctor. (convert_like_real): Avoid copying inheriting ctor parameters. (build_over_call): Likewise. A base ctor inheriting from vbase has no parms. Sorry about varargs. (joust): A local constructor beats inherited with the same convs. * class.c (add_method): Handle hiding inheriting ctors. (one_inherited_ctor): Handle new semantics. (add_implicitly_declared_members): Pass using_decl down. (build_clone): A base ctor inheriting from vbase has no parms. * cp-tree.h (DECL_INHERITED_CTOR): Store this instead of the base. (SET_DECL_INHERITED_CTOR): Likewise. (DECL_INHERITED_CTOR_BASE): Adjust. * constexpr.c: Adjust. * error.c (dump_function_decl): Decorate inheriting ctors. * init.c (emit_mem_initializers): Suppress access control in inheriting ctor. * mangle.c (write_special_name_constructor): Handle new inheriting ctor mangling. * method.c (strip_inheriting_ctors, inherited_ctor_binfo) (ctor_omit_inherited_parms, binfo_inherited_from): New. (synthesized_method_walk): Use binfo_inherited_from. Suppress access control in inheriting ctor. (deduce_inheriting_ctor): Deleted if ambiguous ctor inheritance. (maybe_explain_implicit_delete): Explain ambigous ctor inheritance. (add_one_base_init, do_build_copy_constructor): Adjust. (locate_fn_flags, explain_implicit_non_constexpr): Adjust. (implicitly_declare_fn): Adjust. (get_inherited_ctor): Remove. * name-lookup.c (do_class_using_decl): Check for indirect ctor inheritance. * optimize.c (cdtor_comdat_group): Adjust for new mangling. (maybe_clone_body): Handle omitted parms in base clone. (maybe_thunk_body): Don't thunk if base clone omits parms. * pt.c (tsubst_decl): Adjust. (instantiate_template_1): Suppress access control in inheriting ctor. (fn_type_unification): Do deduction with inherited ctor. * tree.c (special_function_p): Adjust. gcc/ * tree-inline.c (copy_tree_body_r): Only copy the taken branch of a COND_EXPR with constant condition. libiberty/ * cp-demangle.c (d_ctor_dtor_name): Handle inheriting constructor. From-SVN: r241765
* constexpr.c (maybe_constant_init): Pull out TARGET_EXPR_INITIAL.Jason Merrill2016-10-251-0/+16
| | | | | | | | | | * constexpr.c (maybe_constant_init): Pull out TARGET_EXPR_INITIAL. (cxx_eval_outermost_constant_expr): Don't return a CONSTRUCTOR with CONSTRUCTOR_NO_IMPLICIT_ZERO. (cxx_eval_call_expression): Clear CONSTRUCTOR_NO_IMPLICIT_ZERO. From-SVN: r241531
* internal-fn.def (LAUNDER): New internal function.Jakub Jelinek2016-10-251-0/+5
| | | | | | | | | | | | | | | | | | | | * internal-fn.def (LAUNDER): New internal function. * internal-fn.c (expand_LAUNDER): New function. c-family/ * c-common.h (enum rid): Add RID_BUILTIN_LAUNDER. * c-common.c (c_common_reswords): Add __builtin_launder. cp/ * cp-tree.h (finish_builtin_launder): Declare. * parser.c (cp_parser_postfix_expression): Handle RID_BUILTIN_LAUNDER. * semantics.c (finish_builtin_launder): New function. * pt.c (tsubst_copy_and_build): Handle instantiation of IFN_LAUNDER. * constexpr.c (cxx_eval_internal_function): Handle IFN_LAUNDER. (potential_constant_expression_1): Likewise. testsuite/ * g++.dg/cpp1z/launder1.C: New test. * g++.dg/cpp1z/launder2.C: New test. From-SVN: r241506
* PR c++/77945 - constexpr and trivial copyJason Merrill2016-10-151-0/+23
| | | | | | | | * constexpr.c (maybe_simplify_trivial_copy): New. (cxx_eval_store_expression): Call it. * call.c (build_over_call): Use unsigned char for trivial copy. From-SVN: r241204
* Implement LWG2296 helper intrinsic c-family/Jakub Jelinek2016-10-071-0/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | Implement LWG2296 helper intrinsic c-family/ * c-common.h (enum rid): Add RID_ADDRESSOF. * c-common.c (c_common_reswords): Add __builtin_addressof. cp/ * parser.c (cp_parser_postfix_expression): Handle RID_ADDRESSOF. * cp-objcp-common.c (cp_common_init_ts): Handle ADDRESSOF_EXPR. * constexpr.c (potential_constant_expression_1): Likewise. * error.c (dump_expr): Likewise. * typeck.c (cp_build_addressof): New function. * cp-tree.h (cp_build_addressof): Declare. * cxx-pretty-print.h (pp_cxx_addressof_expression): Declare. * cp-tree.def (ADDRESSOF_EXPR): New tree code. * cxx-pretty-print.c (cxx_pretty_printer::primary_expression): Handle ADDRESSOF_EXPR. Add __builtin_addressof and __has_unique_object_representations into syntax in function comment. (pp_cxx_addressof_expression): New function. * pt.c (tsubst_copy_and_build): Handle ADDRESSOF_EXPR. testsuite/ * g++.dg/cpp0x/addressof1.C: New test. * g++.dg/cpp0x/addressof2.C: New test. From-SVN: r240873
* PR c++/77775 - misoptimization of PMF comparisonJason Merrill2016-10-041-1/+7
| | | | | | | * constexpr.c (cxx_eval_component_reference): Use name matching for PMFs. From-SVN: r240757
* re PR c++/77467 (Segmentation fault with switch statement in constexpr function)Jakub Jelinek2016-09-281-29/+87
| | | | | | | | | | | | | | | | | | | | | | | | | | | PR c++/77467 * constexpr.c (enum constexpr_switch_state): New. (struct constexpr_ctx): Add css_state field. (label_matches): Add CTX and STMT arguments, remove I and DEFAULT_LABEL. For CASE_LABEL_EXPR assert ctx->css_state != NULL, handle default labels according to css_state. (cxx_eval_statement_list): Remove statement skipping, label_matches and default_label handling code. (cxx_eval_loop_expr): Exit after first iteration even if switches (jump_target). (cxx_eval_switch_expr): Set up css_state field in ctx, if default label has been seen in the body, but no cases matched, evaluate the body second time. (cxx_eval_constant_expression): Handle stmt skipping and label_matches here. Handle PREDICT_EXPR. For MODIFY_EXPR or INIT_EXPR, assert statement is not skipped. For COND_EXPR during skipping, don't evaluate condition, just the then block and if still skipping at the end also the else block. (cxx_eval_outermost_constant_expr): Adjust constexpr_ctx initializer. (is_sub_constant_expr): Likewise. * g++.dg/cpp1y/constexpr-77467.C: New test. From-SVN: r240591
* Implement -Wimplicit-fallthrough.Marek Polacek2016-09-261-0/+2
| | | | | | Co-Authored-By: Jakub Jelinek <jakub@redhat.com> From-SVN: r240485
* sel-sched-ir.c (sel_global_bb_info, [...]): Remove unnecessary = vNULL ↵Jakub Jelinek2016-09-231-1/+1
| | | | | | | | | | | | | | | | | | | | | initialization of file scope vec. * sel-sched-ir.c (sel_global_bb_info, sel_region_bb_info, loop_nests, s_i_d, last_added_blocks): Remove unnecessary = vNULL initialization of file scope vec. * passes.c (pass_tab, enabled_pass_uid_range_tab, disabled_pass_uid_range_tab): Likewise. * haifa-sched.c (sched_luids, h_i_d): Likewise. * tree-chkp-opt.c (check_infos): Likewise. * sel-sched.c (vec_av_set, vec_temp_moveop_nops): Likewise. c/ * c-parser.c (incomplete_record_decls): Remove unnecessary = vNULL initialization of file scope vec. cp/ * constexpr.c (call_stack): Remove unnecessary = vNULL initialization of file scope vec. From-SVN: r240444
* re PR c++/77626 (ICE with -Wall on x86_64-linux-gnu (internal compiler ↵Jakub Jelinek2016-09-201-9/+5
| | | | | | | | | | | | | error: Segmentation fault, byte_from_pos, cxx_fold_indirect_ref)) PR c++/77626 * constexpr.c (cxx_fold_indirect_ref): Don't call byte_position on FIELD_DECLs with error_mark_node type. Remove useless break; after return. * g++.dg/other/pr77626.C: New test. From-SVN: r240267
* re PR c++/77338 (ICE on invalid C++11 code on x86_64-linux-gnu: Segmentation ↵Jakub Jelinek2016-09-161-1/+2
| | | | | | | | | | | | fault) PR c++/77338 * constexpr.c (cxx_eval_constant_expression) <case PARM_DECL>: Only call is_really_empty_class on complete types. * g++.dg/cpp0x/decltype-77338.C: New test. From-SVN: r240196
* re PR c++/77553 (wrong code with post-increment operator in constexpr)Jakub Jelinek2016-09-131-69/+60
| | | | | | | | | | | | | PR c++/77553 * constexpr.c (cxx_fold_pointer_plus_expression): New function. (cxx_eval_binary_expression): Use it for POINTER_PLUS_EXPR. (cxx_eval_pointer_plus_expression): Remove. (cxx_eval_constant_expression) <case POINTER_PLUS_EXPR>: Don't call cxx_eval_pointer_plus_expression. * g++.dg/cpp1y/constexpr-77553.C: New test. From-SVN: r240119
* re PR c/7652 (-Wswitch-break : Warn if a switch case falls through)Marek Polacek2016-08-121-3/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | PR c/7652 gcc/ * alias.c (find_base_value): Adjust fall through comment. * cfgexpand.c (expand_debug_expr): Likewise. * combine.c (find_split_point): Likewise. (expand_compound_operation): Likewise. Add FALLTHRU. (make_compound_operation): Adjust fall through comment. (canon_reg_for_combine): Add FALLTHRU. (force_to_mode): Adjust fall through comment. (simplify_shift_const_1): Likewise. (simplify_comparison): Likewise. * config/aarch64/aarch64-builtins.c (aarch64_simd_expand_args): Add FALLTHRU. * config/aarch64/predicates.md: Likewise. * config/i386/i386.c (function_arg_advance_32): Likewise. (ix86_gimplify_va_arg): Likewise. (print_reg): Likewise. (ix86_print_operand): Likewise. (ix86_build_const_vector): Likewise. (ix86_expand_branch): Likewise. (ix86_sched_init_global): Adjust fall through comment. (ix86_expand_args_builtin): Add FALLTHRU. (ix86_expand_builtin): Likewise. (ix86_expand_vector_init_one_var): Likewise. * config/rs6000/rs6000.c (rs6000_emit_vector_compare_inner): Likewise. (rs6000_adjust_cost): Likewise. (insn_must_be_first_in_group): Likewise. * config/rs6000/rs6000.md: Likewise. Adjust fall through comment. * dbxout.c (dbxout_symbol): Adjust fall through comment. * df-scan.c (df_uses_record): Likewise. * dojump.c (do_jump): Add FALLTHRU. * dwarf2out.c (mem_loc_descriptor): Likewise. Adjust fall through comment. (resolve_args_picking_1): Adjust fall through comment. (loc_list_from_tree_1): Likewise. * expmed.c (make_tree): Likewise. * expr.c (expand_expr_real_2): Add FALLTHRU. (expand_expr_real_1): Likewise. Adjust fall through comment. * fold-const.c (const_binop): Adjust fall through comment. (fold_truth_not_expr): Likewise. (fold_cond_expr_with_comparison): Add FALLTHRU. (fold_binary_loc): Likewise. (contains_label_1): Adjust fall through comment. (multiple_of_p): Likewise. * gcov-tool.c (process_args): Add FALLTHRU. * genattrtab.c (check_attr_test): Likewise. (write_test_expr): Likewise. * genconfig.c (walk_insn_part): Likewise. * genpreds.c (validate_exp): Adjust fall through comment. (needs_variable): Likewise. * gensupport.c (get_alternatives_number): Add FALLTHRU. (subst_dup): Likewise. * gimple-pretty-print.c (dump_gimple_assign): Likewise. * gimplify.c (gimplify_addr_expr): Adjust fall through comment. (gimplify_scan_omp_clauses): Add FALLTHRU. (goa_stabilize_expr): Likewise. * graphite-isl-ast-to-gimple.c (substitute_ssa_name): Adjust fall through comment. * hsa-gen.c (get_address_from_value): Likewise. * ipa-icf.c (sem_function::hash_stmt): Likewise. * ira.c (ira_setup_alts): Add FALLTHRU. * lra-eliminations.c (lra_eliminate_regs_1): Adjust fall through comment. * lto-streamer-out.c (lto_output_tree_ref): Add FALLTHRU. * opts.c (common_handle_option): Likewise. * read-rtl.c (read_rtx_code): Likewise. * real.c (round_for_format): Likewise. * recog.c (asm_operand_ok): Likewise. * reginfo.c (reg_scan_mark_refs): Adjust fall through comment. * reload1.c (set_label_offsets): Likewise. (eliminate_regs_1): Likewise. (reload_reg_reaches_end_p): Likewise. * rtlanal.c (commutative_operand_precedence): Add FALLTHRU. (rtx_cost): Likewise. * sched-rgn.c (is_exception_free): Likewise. * simplify-rtx.c (simplify_rtx): Adjust fall through comment. * stor-layout.c (int_mode_for_mode): Likewise. * toplev.c (print_to_asm_out_file): Likewise. (print_to_stderr): Likewise. * tree-cfg.c (gimple_verify_flow_info): Likewise. * tree-chrec.c (chrec_fold_plus_1): Add FALLTHRU. (chrec_fold_multiply): Likewise. (evolution_function_is_invariant_rec_p): Likewise. (for_each_scev_op): Likewise. * tree-data-ref.c (siv_subscript_p): Likewise. (get_references_in_stmt): Likewise. * tree.c (find_placeholder_in_expr): Adjust fall through comment. (substitute_in_expr): Likewise. (type_cache_hasher::equal): Likewise. (walk_type_fields): Likewise. * var-tracking.c (adjust_mems): Add FALLTHRU. (set_dv_changed): Adjust fall through comment. * varasm.c (default_function_section): Add FALLTHRU. gcc/c-family/ * c-common.c (scalar_to_vector): Adjust fall through comment. * c-opts.c (c_common_handle_option): Likewise. * c-pragma.c (handle_pragma_pack): Add FALLTHRU. * c-pretty-print.c (c_pretty_printer::postfix_expression): Adjust fall through comment. * cilk.c (extract_free_variables): Add FALLTHRU. gcc/c/ * c-parser.c (c_parser_external_declaration): Add FALLTHRU. (c_parser_postfix_expression): Likewise. * c-typeck.c (build_unary_op): Adjust fall through comment. (c_mark_addressable): Likewise. gcc/cp/ * call.c (add_builtin_candidate): Add FALLTHRU. (build_integral_nontype_arg_conv): Adjust fall through comment. (build_new_op_1): Add FALLTHRU. (convert_like_real): Adjust fall through comment. * class.c (fixed_type_or_null): Likewise. * constexpr.c (cxx_eval_constant_expression): Likewise. (potential_constant_expression_1): Likewise. Add FALLTHRU. * cp-gimplify.c (cp_gimplify_expr): Adjust fall through comment. (cp_fold): Add FALLTHRU. * cvt.c (build_expr_type_conversion): Adjust fall through comment. * cxx-pretty-print.c (pp_cxx_unqualified_id): Add FALLTHRU. (pp_cxx_qualified_id): Likewise. (cxx_pretty_printer::constant): Adjust fall through comment. (cxx_pretty_printer::primary_expression): Add FALLTHRU. (pp_cxx_pm_expression): Adjust fall through comment. (cxx_pretty_printer::expression): Add FALLTHRU. (cxx_pretty_printer::declaration_specifiers): Reformat code. (pp_cxx_type_specifier_seq): Adjust fall through comment. (pp_cxx_ptr_operator): Likewise. Add FALLTHRU. * error.c (dump_type): Adjust fall through comment. (dump_decl): Likewise. * mangle.c (write_type): Likewise. * method.c (synthesized_method_walk): Add FALLTHRU. * name-lookup.c (arg_assoc_type): Likewise. * parser.c (cp_lexer_print_token): Adjust fall through comment. (cp_parser_primary_expression): Add FALLTHRU. (cp_parser_operator): Likewise. * pt.c (find_parameter_packs_r): Likewise. (tsubst_aggr_type): Adjust fall through comment. * semantics.c (finish_omp_clauses): Add FALLTHRU. * tree.c (lvalue_kind): Likewise. gcc/fortran/ * decl.c (match_attr_spec): Add FALLTHRU. * primary.c (match_arg_list_function): Likewise. * resolve.c (resolve_operator): Adjust fall through comment. (fixup_charlen): Add FALLTHRU. (resolve_allocate_expr): Adjust fall through comment. * trans-array.c (gfc_conv_ss_startstride): Add FALLTHRU. * trans-intrinsic.c (gfc_conv_intrinsic_len): Adjust fall through comment. gcc/java/ * expr.c (java_truthvalue_conversion): Adjust fall through comment. * jcf-io.c (verify_constant_pool): Likewise. * typeck.c (promote_type): Likewise. gcc/objc/ * objc-encoding.c (encode_type): Add FALLTHRU. libcpp/ * lex.c (search_line_fast): Add FALLTHRU. (_cpp_lex_direct): Likewise. (cpp_token_val_index): Adjust fall through comment. * macro.c (parse_params): Add FALLTHRU. * pch.c (count_defs): Adjust fall through comment. (write_defs): Likewise. libiberty/ * cp-demangle.c (d_print_mod): Add FALLTHRU. From-SVN: r239410
* re PR c++/72868 (Constexpr expressions mistreat case ranges)Jakub Jelinek2016-08-111-0/+6
| | | | | | | | | PR c++/72868 * constexpr.c (label_matches): Handle case range expressions. * g++.dg/cpp1y/constexpr-switch4.C: New test. From-SVN: r239379
* PR c++/72849 - ICE with incomplete class.Jason Merrill2016-08-091-1/+2
| | | | | | | | * constexpr.c (cxx_eval_constant_expression): Check COMPLETE_TYPE_P before calling is_really_empty_class. * class.c (is_really_empty_class): Don't call complete_type. From-SVN: r239289
* Implement C++17 constexpr lambda.Jason Merrill2016-08-091-11/+75
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | gcc/c-family/ * c-cppbuiltin.c (c_cpp_builtins): Update __cpp_constexpr for C++17 constexpr lambdas. gcc/cp/ * class.c (finalize_literal_type_property): Handle lambdas. * constexpr.c (is_valid_constexpr_fn): Likewise. No longer static. (explain_invalid_constexpr_fn, cxx_eval_call_expression): Handle lambdas. (cxx_eval_constant_expression): Handle capture proxy. (var_in_constexpr_fn): Don't check for C++14. (var_in_maybe_constexpr_fn): New. (potential_constant_expression_1): Use it. Check DECL_EXPR for declarations not allowed in constexpr function. * decl.c (make_rtl_for_nonlocal_decl): Use var_in_maybe_constexpr_fn. (finish_function): Set DECL_DECLARED_CONSTEXPR_P on lambda members. * lambda.c (begin_lambda_type): Set CLASSTYPE_LITERAL_P. (maybe_add_lambda_conv_op): Clear thunk CALL_EXPR location. (lambda_static_thunk_p): New. * parser.c (cp_keyword_starts_decl_specifier_p): Add RID_CONSTEXPR. (CP_PARSER_FLAGS_ONLY_MUTABLE_OR_CONSTEXPR): New enumerator. (cp_parser_decl_specifier_seq): Handle it. (cp_parser_lambda_declarator_opt): Use cp_parser_decl_specifier_seq. * pt.c (instantiate_class_template_1): Set CLASSTYPE_LITERAL_P. (tsubst_copy_and_build) [CALL_EXPR]: Propagate CALL_FROM_THUNK_P. * error.c (dump_function_decl): Check TFF_NO_TEMPLATE_BINDINGS. (dump_expr) [FUNCTION_DECL]: Pass it. From-SVN: r239268
* Fix empty class parameters with constexpr.Jason Merrill2016-08-091-4/+15
| | | | | | | | | | PR c++/67131 * class.c (is_really_empty_class): Call complete_type. * constexpr.c (cxx_eval_constant_expression): Check is_really_empty_class. (potential_constant_expression_1): Likewise. Check for error type. From-SVN: r239267
* constexpr.c (cxx_eval_store_expression): Remove hyphen from the spelling of ↵Martin Sebor2016-08-051-11/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | "constant-expression" in diagnostic messages... gcc/cp/ChangeLog: * constexpr.c (cxx_eval_store_expression): Remove hyphen from the spelling of "constant-expression" in diagnostic messages for consistency. (cxx_eval_constant_expression): Same. (cxx_eval_outermost_constant_expr): Same. (potential_constant_expression_1): Same. gcc/testsuite/ChangeLog: * g++.dg/cpp0x/constexpr-cast.C: Avoid assuming (void*)1 is spelled 1ul in diagnostics. Remove hyphen from "constant-expression." * g++.dg/cpp0x/constexpr-50060.C: Adjust. * g++.dg/cpp0x/static_assert3.C: Same. * g++.dg/cpp1y/constexpr-throw.C: Same. * g++.dg/template/nontype3.C: Same. * g++.dg/warn/overflow-warn-1.C: Same. * g++.dg/warn/overflow-warn-3.C: Same. * g++.dg/warn/overflow-warn-4.C: Same. From-SVN: r239176
* re PR c++/70229 (error: constexpr constructor does not have empty body)Marek Polacek2016-08-041-1/+2
| | | | | | | | | | PR c++/70229 * constexpr.c (check_constexpr_ctor_body_1): Allow typedef declarations. * g++.dg/cpp0x/constexpr-ctor19.C: New test. From-SVN: r239115
* PR c++/72766 - ICE with VLAJason Merrill2016-08-011-0/+4
| | | | | | | | | * constexpr.c (cxx_eval_pointer_plus_expression): Check constancy of nelts. * cp-gimplify.c (cp_fully_fold): Only maybe_constant_value in C++11 and up. From-SVN: r238957
* PR c++/60760 - arithmetic on null pointers should not be allowed in constantMartin Sebor2016-07-301-10/+74
| | | | | | | | | | | | | | | | | | | | | | | | | | | PR c++/60760 - arithmetic on null pointers should not be allowed in constant PR c++/71091 - constexpr reference bound to a null pointer dereference gcc/cp/ChangeLog: PR c++/60760 PR c++/71091 * constexpr.c (cxx_eval_binary_expression): Reject invalid expressions involving null pointers. (cxx_eval_component_reference): Reject null pointer dereferences. (cxx_eval_indirect_ref): Reject indirecting through null pointers. (cxx_eval_constant_expression): Reject invalid expressions involving null pointers. gcc/testsuite/ChangeLog: PR c++/60760 PR c++/71091 * g++.dg/cpp0x/constexpr-cast.C: New test. * g++.dg/cpp0x/constexpr-nullptr-2.C: New test. * g++.dg/cpp1y/constexpr-sfinae.C: Correct. * g++.dg/ubsan/pr63956.C: Correct. From-SVN: r238909
* PR c++/72457 - ICE with list-value-initialized base.Jason Merrill2016-07-291-1/+6
| | | | | | | | * init.c (expand_aggr_init_1): Only handle value-init of bases. * constexpr.c (build_data_member_initialization): Handle multiple initializers for the same field. From-SVN: r238867
* PR c++/65970 - constexpr infinite loopJason Merrill2016-07-251-0/+11
| | | | | | | | | | | gcc/c-family/ * c.opt (fconstexpr-loop-limit): New. gcc/cp/ * constexpr.c (cxx_eval_loop_expr): Count iterations. * cp-gimplify.c (genericize_cp_loop): Use start_locus even for infinite loops. From-SVN: r238730
* PR c++/71972 - constexpr array self-modificationJason Merrill2016-07-251-28/+35
| | | | | | | * constexpr.c (cxx_eval_array_reference): Handle looking for the value of an element we're currently modifying. From-SVN: r238729
* re PR c++/71728 (ICE with goto in statement-expression inside a condition)Jakub Jelinek2016-07-211-5/+7
| | | | | | | | | | | PR c++/71728 * constexpr.c (potential_constant_expression_1) <case GOTO_EXPR>: Replace assert with test, return false if the goto isn't break or continue. Formatting fix. * g++.dg/other/pr71728.C: New test. From-SVN: r238601
* PR c++/71896 - constexpr pointer-to-member comparison.Jason Merrill2016-07-211-0/+4
| | | | | | | * constexpr.c (cxx_eval_binary_expression): Handle comparison between lowered and unlowered PTRMEM_CST. From-SVN: r238562
* re PR middle-end/50060 (intrinsics not folded by the middle-end)Jakub Jelinek2016-07-201-7/+25
| | | | | | | | | | | | | | PR c++/50060 * constexpr.c (cxx_eval_builtin_function_call): Pass false as lval when evaluating call arguments. Use fold_builtin_call_array instead of fold_build_call_array_loc, return t if it returns NULL. Otherwise check the result with potential_constant_expression and call cxx_eval_constant_expression on it. * g++.dg/cpp0x/constexpr-50060.C: New test. * g++.dg/cpp1y/constexpr-50060.C: New test. From-SVN: r238520
* re PR c++/71828 (ICE on valid C++11 code with constexpr __Complex int ↵Jakub Jelinek2016-07-181-0/+13
| | | | | | | | | | | | | variable declaration: in operand_equal_p, at fold-const.c:2790) PR c++/71828 * constexpr.c (cxx_eval_constant_expression) <case REALPART_EXPR>: For lval don't use cxx_eval_unary_expression and instead recurse and if needed rebuild the reference. * g++.dg/cpp0x/constexpr-71828.C: New test. From-SVN: r238442
* PR c++/71092 - ICE with array and constexpr.Jason Merrill2016-07-151-2/+12
| | | | | | | * constexpr.c (cxx_eval_call_expression): Fail quietly when cgraph threw away DECL_SAVED_TREE. From-SVN: r238395
* Use lvalue_p instead of real_lvalue_p.Jason Merrill2016-07-081-1/+1
| | | | | | | | | * cp-tree.h: Unpoison lvalue_p. * call.c, class.c, constexpr.c, cvt.c, init.c, lambda.c, pt.c, tree.c, typeck.c, typeck2.c: Use lvalue_p instead of real_lvalue_p. From-SVN: r238183
* re PR c++/70507 (integer overflow builtins not constant expressions)Martin Sebor2016-06-081-19/+88
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | PR c++/70507 PR c/68120 * builtins.def (BUILT_IN_ADD_OVERFLOW_P, BUILT_IN_SUB_OVERFLOW_P, BUILT_IN_MUL_OVERFLOW_P): New builtins. * builtins.c: Include gimple-fold.h. (fold_builtin_arith_overflow): Handle BUILT_IN_{ADD,SUB,MUL}_OVERFLOW_P. (fold_builtin_3): Likewise. * doc/extend.texi (Integer Overflow Builtins): Document __builtin_{add,sub,mul}_overflow_p. gcc/c/ * c-typeck.c (convert_arguments): Don't promote last argument of BUILT_IN_{ADD,SUB,MUL}_OVERFLOW_P. gcc/cp/ * constexpr.c: Include gimple-fold.h. (cxx_eval_internal_function): New function. (cxx_eval_call_expression): Call it. (potential_constant_expression_1): Handle integer arithmetic overflow built-ins. * tree.c (builtin_valid_in_constant_expr_p): Handle BUILT_IN_{ADD,SUB,MUL}_OVERFLOW_P. gcc/c-family/ * c-common.c (check_builtin_function_arguments): Handle BUILT_IN_{ADD,SUB,MUL}_OVERFLOW_P. gcc/testsuite/ * c-c++-common/builtin-arith-overflow-1.c: Add test cases. * c-c++-common/builtin-arith-overflow-2.c: New test. * g++.dg/ext/builtin-arith-overflow-1.C: New test. * g++.dg/cpp0x/constexpr-arith-overflow.C: New test. * g++.dg/cpp1y/constexpr-arith-overflow.C: New test. Co-Authored-By: Jakub Jelinek <jakub@redhat.com> From-SVN: r237238
* re PR middle-end/70434 (adding an extraneous cast to vector type results in ↵Richard Biener2016-05-241-1/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | inferior code) 2016-05-24 Richard Biener <rguenther@suse.de> PR middle-end/70434 PR c/69504 c-family/ * c-common.h (convert_vector_to_pointer_for_subscript): Rename to ... (convert_vector_to_array_for_subscript): ... this. * c-common.c (convert_vector_to_pointer_for_subscript): Use a VIEW_CONVERT_EXPR to an array type. Rename to ... (convert_vector_to_array_for_subscript): ... this. cp/ * expr.c (mark_exp_read): Handle VIEW_CONVERT_EXPR. * constexpr.c (cxx_eval_array_reference): Handle indexed vectors. * typeck.c (cp_build_array_ref): Adjust. c/ * c-typeck.c (build_array_ref): Do not complain about indexing non-lvalue vectors. Adjust for function name change. * tree-ssa.c (non_rewritable_mem_ref_base): Make sure to mark bases which are accessed with non-invariant indices. * gimple-fold.c (maybe_canonicalize_mem_ref_addr): Re-write constant index ARRAY_REFs of vectors into BIT_FIELD_REFs. * c-c++-common/vector-subscript-4.c: New testcase. * c-c++-common/vector-subscript-5.c: Likewise. From-SVN: r236630
* PR c++/70344 - ICE with recursive constexprJason Merrill2016-05-231-2/+8
| | | | | | | * constexpr.c (cxx_eval_call_expression): Check for fun == current_function_decl again. From-SVN: r236625
* constexpr.c (cxx_bind_parameters_in_call): Avoid gratuitous if ...Nathan Sidwell2016-05-201-13/+13
| | | | | | | | * constexpr.c (cxx_bind_parameters_in_call): Avoid gratuitous if ... goto. (cxx_eval_call_expression): Fix comment grammar. From-SVN: r236543
* cvt.c (cp_get_callee): New.Jason Merrill2016-04-281-15/+1
| | | | | | | | | | | | | * cvt.c (cp_get_callee): New. * constexpr.c (get_function_named_in_call): Use it. * cxx-pretty-print.c (postfix_expression): Use it. * except.c (check_noexcept_r): Use it. * method.c (check_nontriv): Use it. * tree.c (build_aggr_init_expr): Use it. * cp-tree.h: Declare it. From-SVN: r235596
* constexpr.c (get_fundef_copy): Use the original function for non-recursive ↵Nathan Sidwell2016-04-271-6/+20
| | | | | | | | | | | | | | | evaluations. cp/ * constexpr.c (get_fundef_copy): Use the original function for non-recursive evaluations. (save_fundef_copy): Always expect a slot to be available. testsuite/ * g++.dg/cpp0x/constexpr-recursion3.C: New. * g++.dg/ubsan/pr63956.C: Adjust error location. From-SVN: r235506
* Improve constexpr handling of other loop forms.Jason Merrill2016-04-191-4/+18
| | | | | | | | | * constexpr.c (breaks): Handle EXIT_EXPR. (cxx_eval_loop_expr): Handle COMPOUND_EXPR body. (cxx_eval_constant_expression): Handle EXIT_EXPR, improve handling of COMPOUND_EXPR. From-SVN: r235218
* PR c++/68206 - Fix constexpr diagnostics with loops.Jason Merrill2016-04-191-0/+11
| | | | | | | | PR c++/68530 * constexpr.c (potential_constant_expression_1): Handle LOOP_EXPR and GOTO_EXPR. From-SVN: r235217
* re PR c++/70685 (ICE: Segmentation fault)Jason Merrill2016-04-151-1/+1
| | | | | | | PR c++/70685 * constexpr.c (get_fundef_copy): Handle null *slot. From-SVN: r235045
* re PR c++/70594 (-fcompare-debug failure)Jason Merrill2016-04-151-36/+32
| | | | | | | | | | | | | | | | | | | PR c++/70594 * constexpr.c (constexpr_call_table): Preserve in GC. (struct fundef_copy, struct fundef_copies_table_t): Delete. (fundef_copies_table): Preserve in GC. Change to pointer to tree->tree hash. (maybe_initialize_fundef_copies_table): Adjust. (get_fundef_copy): Return a TREE_LIST. Use non-inserting search. (save_fundef_copy): Adjust for a TREE_LIST. (cxx_eval_call_expression): Adjust for a fundef_copy TREE_LIST. (fini_constexpr): New. * cp-tree.h (fini_constexpr): Declare. * decl2.c (c_parse_final_cleanups): Call fini_constexpr. Co-Authored-By: Nathan Sidwell <nathan@acm.org> From-SVN: r235033
* re PR c++/70648 (adplug-xmms fails to compile)Jason Merrill2016-04-141-0/+2
| | | | | | | | | PR c++/70648 * constexpr.c (cxx_eval_store_expression): Also copy CONSTRUCTOR_NO_IMPLICIT_ZERO. From-SVN: r234989
* constexpr.c (potential_nondependent_constant_expression): New.Jason Merrill2016-04-131-10/+28
| | | | | | | | | | | | | * constexpr.c (potential_nondependent_constant_expression): New. (potential_nondependent_static_init_expression): New. (maybe_constant_value_1, fold_non_dependent_expr) (maybe_constant_init): Use them. * pt.c (instantiate_non_dependent_expr_sfinae) (instantiate_non_dependent_or_null, convert_nontype_argument): Use them. * cp-tree.h: Declare them. From-SVN: r234944
* re PR c++/70501 (internal compiler error: in verify_ctor_sanity, at ↵Nathan Sidwell2016-04-121-3/+3
| | | | | | | | | | | | | | | cp/constexpr.c:2249) PR c++/70501 cp/ * constexpr.c (cxx_eval_bare_aggregate): Handle VECTOR_TYPE similarly to PMF. testsuite/ * g++.dg/init/pr70501.C: New. From-SVN: r234904