https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91369

--- Comment #10 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Author: jakub
Date: Sat Oct  5 07:38:21 2019
New Revision: 276622

URL: https://gcc.gnu.org/viewcvs?rev=276622&root=gcc&view=rev
Log:
        PR c++/91369 - Implement P0784R7: constexpr new
c-family/
        * c-cppbuiltin.c (c_cpp_builtins): Predefine
        __cpp_constexpr_dynamic_alloc=201907 for -std=c++2a.
cp/
        * cp-tree.h (enum cp_tree_index): Add CPTI_HEAP_UNINIT_IDENTIFIER,
        CPTI_HEAP_IDENTIFIER and CPTI_HEAP_DELETED_IDENTIFIER.
        (heap_uninit_identifier, heap_identifier, heap_deleted_identifier):
        Define.
        (type_has_constexpr_destructor, build_new_constexpr_heap_type,
        cxx_constant_dtor): Declare.
        * class.c (type_maybe_constexpr_default_constructor): Make static.
        (type_maybe_constexpr_destructor, type_has_constexpr_destructor): New
        functions.
        (finalize_literal_type_property): For c++2a, don't clear
        CLASSTYPE_LITERAL_P for types without trivial destructors unless they
        have non-constexpr destructors.
        (explain_non_literal_class): For c++2a, complain about non-constexpr
        destructors rather than about non-trivial destructors.
        * constexpr.c: Include stor-layout.h.
        (struct constexpr_global_ctx): New type.
        (struct constexpr_ctx): Add global field, remove values and
        constexpr_ops_count.
        (cxx_replaceable_global_alloc_fn): New inline function.
        (cxx_eval_call_expression): For c++2a allow calls to replaceable
        global allocation functions, for new return address of a heap uninit
        var, for delete record its deletion.  Change ctx->values->{get,put} to
        ctx->global->values.{get,put}.
        (non_const_var_error): Add auto_diagnostic_group sentinel.  Emit
        special diagnostics for heap variables.
        (cxx_eval_store_expression): Change ctx->values->{get,put} to
        ctx->global->values.{get,put}.
        (cxx_eval_loop_expr): Initialize jump_target if NULL.  Change
        new_ctx.values->remove to ctx->global->values.remove.
        (cxx_eval_constant_expression): Change *ctx->constexpr_ops_count
        to ctx->global->constexpr_ops_count.  Change ctx->values->{get,put} to
        ctx->global->values.{get,put}.
        <case NOP_EXPR>: Formatting fix.  On cast of replaceable global
        allocation function to some pointer type, adjust the type of
        the heap variable and change name from heap_uninit_identifier
        to heap_identifier.
        (find_heap_var_refs): New function.
        (cxx_eval_outermost_constant_expr): Add constexpr_dtor argument,
        handle evaluation of constexpr dtors and add tracking of heap
        variables.  Use tf_no_cleanup for get_target_expr_with_sfinae.
        (cxx_constant_value): Adjust cxx_eval_outermost_constant_expr caller.
        (cxx_constant_dtor): New function.
        (maybe_constant_value, fold_non_dependent_expr_template,
        maybe_constant_init_1): Adjust cxx_eval_outermost_constant_expr
        callers.
        (potential_constant_expression_1): Ignore clobbers.  Allow
        COND_EXPR_IS_VEC_DELETE for c++2a.
        * decl.c (initialize_predefined_identifiers): Add heap identifiers.
        (decl_maybe_constant_destruction): New function.
        (cp_finish_decl): Don't clear TREE_READONLY for constexpr variables
        with non-trivial, but constexpr destructors.
        (register_dtor_fn): For constexpr variables with constexpr non-trivial
        destructors call cxx_maybe_build_cleanup instead of adding destructor
        calls at runtime.
        (expand_static_init): For constexpr variables with constexpr
        non-trivial destructors call cxx_maybe_build_cleanup.
        (grokdeclarator): Allow constexpr destructors for c++2a.  Formatting
        fix.
        (cxx_maybe_build_cleanup): For constexpr variables with constexpr
        non-trivial destructors call cxx_constant_dtor instead of adding
        destructor calls at runtime.
        * init.c: Include stor-layout.h.
        (build_new_constexpr_heap_type, maybe_wrap_new_for_constexpr): New
        functions.
        (build_new_1): For c++2a and new[], add cast around the alloc call
        to help constexpr evaluation figure out the type of the heap storage.
        (build_vec_delete_1): Set DECL_INITIAL of tbase and emit a DECL_EXPR
        for it instead of initializing an uninitialized variable.
        * method.c: Include intl.h.
        (SFK_CTOR_P, SFK_DTOR_P, SFK_ASSIGN_P, SFK_COPY_P, SFK_MOVE_P): Move
        definitions earlier.
        (process_subob_fn): Add sfk argument, adjust non-constexpr call
        diagnostics based on it.
        (walk_field_subobs): Formatting fixes.  Adjust process_subob_fn caller.
        (synthesized_method_base_walk): Likewise.
        (synthesized_method_walk): Set *constexpr_p to true for dtors in c++2a.
        Fix up DR number in comment.
        (implicitly_declare_fn): Formatting fix.
        * typeck2.c (store_init_value): Don't call cp_fully_fold_init on
        initializers of automatic non-constexpr variables in constexpr
        functions.
testsuite/
        * g++.dg/cpp0x/constexpr-delete2.C: Adjust expected diagnostics for
        c++2a.
        * g++.dg/cpp0x/locations1.C: Only expect constexpr ~S() diagnostics
        in c++17_down, adjust expected wording.
        * g++.dg/cpp1y/constexpr-new.C: Only expect diagnostics in c++17_down.
        * g++.dg/cpp2a/constexpr-dtor1.C: New test.
        * g++.dg/cpp2a/constexpr-dtor2.C: New test.
        * g++.dg/cpp2a/constexpr-dtor3.C: New test.
        * g++.dg/cpp2a/constexpr-new1.C: New test.
        * g++.dg/cpp2a/constexpr-new2.C: New test.
        * g++.dg/cpp2a/constexpr-new3.C: New test.
        * g++.dg/cpp2a/constexpr-new4.C: New test.
        * g++.dg/cpp2a/feat-cxx2a.C: Add __cpp_constinit and
        __cpp_constexpr_dynamic_alloc tests.  Tweak __cpp_* tests for c++2a
        features to use style like older features, including #ifdef test.
        * g++.dg/ext/is_literal_type3.C: New test.

Added:
    trunk/gcc/testsuite/g++.dg/cpp2a/constexpr-dtor1.C
    trunk/gcc/testsuite/g++.dg/cpp2a/constexpr-dtor2.C
    trunk/gcc/testsuite/g++.dg/cpp2a/constexpr-dtor3.C
    trunk/gcc/testsuite/g++.dg/cpp2a/constexpr-new1.C
    trunk/gcc/testsuite/g++.dg/cpp2a/constexpr-new2.C
    trunk/gcc/testsuite/g++.dg/cpp2a/constexpr-new3.C
    trunk/gcc/testsuite/g++.dg/cpp2a/constexpr-new4.C
    trunk/gcc/testsuite/g++.dg/ext/is_literal_type3.C
Modified:
    trunk/gcc/c-family/ChangeLog
    trunk/gcc/c-family/c-cppbuiltin.c
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/class.c
    trunk/gcc/cp/constexpr.c
    trunk/gcc/cp/cp-tree.h
    trunk/gcc/cp/decl.c
    trunk/gcc/cp/init.c
    trunk/gcc/cp/method.c
    trunk/gcc/cp/typeck2.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/g++.dg/cpp0x/constexpr-delete2.C
    trunk/gcc/testsuite/g++.dg/cpp0x/locations1.C
    trunk/gcc/testsuite/g++.dg/cpp1y/constexpr-new.C
    trunk/gcc/testsuite/g++.dg/cpp2a/feat-cxx2a.C

Reply via email to