From patchwork Tue Oct 29 16:24:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 99781 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 355BF3858431 for ; Tue, 29 Oct 2024 16:25:41 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id D8DE93858C98 for ; Tue, 29 Oct 2024 16:25:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D8DE93858C98 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org D8DE93858C98 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1730219109; cv=none; b=Y8cyC8fQhi7IXiWasVrDPuG5ht9oJixMhliRWBg6K2foKo9nzrFZ1aEs/HvxI7xJSdY1bZ7NuY9t3OXrfCR4B+TtrLZF3yDyDsZ7wnTuZ9eLvwqZJyhKi24uSfQQTTJ4H5IXfcUl4MQU9z5TWfaOhd2cYBNhWl2V4YcVB4xFKe0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1730219109; c=relaxed/simple; bh=msrOiO+2kHJWeUCgkrt1whVoltdasJLDR2TX2MaAO7g=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=kJ9XfWOoetSEFKI4RgTyyl1/fj89AYI2ddqbWS7te2OC9Xkc4lQ3+sXxJInFziZ2W810cW+rwCismlXoFMnsxS33Di7Y2RLbxHYhM+smgNgr3WUI5kb1BJXgFHluq32CSP435OpP/1yPZdOgCsGP9dzcbsRdfMpTyqOOBTGS29E= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1730219102; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Ogg2zd4EVIon6JLw4MiUaRBgkQDTln0M9Pm37zNyiWM=; b=NuC40MdUzaQDu/Xzea3IESlZtENP62Y5KnMeX/NRlNs1uGjlBSqzYaWFCnWLEvnazDPLuW ixNoivfZoYctOx9VvvIE01kvWdurLRqD4/BtFFqoKThfJsYzhN9pdD5LbJWfqgevBzwvbZ mLT5z0PKqftyqEC2GrBc1xrAFNNQxT8= Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-422-hZ_y1IOdP7mV6Y4rVdRJTw-1; Tue, 29 Oct 2024 12:25:00 -0400 X-MC-Unique: hZ_y1IOdP7mV6Y4rVdRJTw-1 Received: by mail-qk1-f200.google.com with SMTP id af79cd13be357-7b14073eabdso1049693285a.3 for ; Tue, 29 Oct 2024 09:25:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730219099; x=1730823899; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Ogg2zd4EVIon6JLw4MiUaRBgkQDTln0M9Pm37zNyiWM=; b=W/6Uum1IXOGjyWAAkceeJpVwK22H/z3+WwQQSqUm+kJlZu5A0+53WIPwcL+8O9Dud2 KiootLaiDJX5Cl3Ejtd+jFwm0Qrq3xq5LR+bn3b/Y3VSkL958FqA6oTAzHMhTb+d0NQd F7pDYO29XvK7s0YBmRUQqPdyggVr0wataFv0NYnN4XRIG5fCMkYMO0eFLyFSGREW8+ch 8P6iCDs5loMmjRSTtg7jebHrygLehBjj/nvC0Q58w2lfLh2rL1tStPF6gXHMIJa2t7Su GFm+RoUjEnwczDRfv55WKcE8yqrZQj/PsasdLV1Me0dK4NEioeMEp7I1Ui63yDLGyUS0 0uig== X-Gm-Message-State: AOJu0YxinYFtOOYW7HuOmFNA3JQJtfIj62mg/aqUZhgLqU4wiOH/yAAV DA3c3NCjjbfPsQVaHdKGsSzpJjsjJiIozS4M3mzhJzszVrnKB0aO7R5lgydhecJKS1I56LNSSKG SLLXSpTNH5yo74XZMTmHPKgl7+ySXiQIwIX65PMuQbmwvEjIAw4l1PJEIB68Q6HOLE4Z8RuimOm k9e5YtyPR/GMjFsR711P/q0ncKtLIeDfWTSCo= X-Received: by 2002:a05:620a:1a11:b0:7b1:4823:fa84 with SMTP id af79cd13be357-7b193eed7f4mr1828002785a.16.1730219099138; Tue, 29 Oct 2024 09:24:59 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHXMsf7aFxpoDHaB2LsUQO+yS4VlllPJcKmA65gfZhG2r7av/wfF8H/3EWL+UVwY2GautSZYw== X-Received: by 2002:a05:620a:1a11:b0:7b1:4823:fa84 with SMTP id af79cd13be357-7b193eed7f4mr1827998085a.16.1730219098473; Tue, 29 Oct 2024 09:24:58 -0700 (PDT) Received: from jason-thinkpadp1gen4i.rmtusma.csb (130-44-146-16.s12558.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.146.16]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7b18d27b8f7sm431921985a.22.2024.10.29.09.24.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Oct 2024 09:24:58 -0700 (PDT) From: Jason Merrill To: gcc-patches@gcc.gnu.org Subject: [pushed] c++: printing AGGR_INIT_EXPR args Date: Tue, 29 Oct 2024 12:24:43 -0400 Message-ID: <20241029162456.3790172-1-jason@redhat.com> X-Mailer: git-send-email 2.47.0 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.3 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~patchwork=sourceware.org@gcc.gnu.org Tested x86_64-pc-linux-gnu, applying to trunk. -- 8< -- PR30854 was about wrongly dumping the dummy object argument to a constructor; r126582 in 4.3 fixed that by skipping the first argument. But not all functions called by AGGR_INIT_EXPR are constructors, as observed in PR116634; we shouldn't skip for non-member functions. And let's combine the printing code for CALL_EXPR and AGGR_INIT_EXPR. This doesn't make us accept the ill-formed 116634 testcase again with a pedwarn, just fixes the diagnostic issue. PR c++/30854 PR c++/116634 gcc/cp/ChangeLog: * error.cc (dump_aggr_init_expr_args): Remove. (dump_call_expr_args): Handle AGGR_INIT_EXPR. (dump_expr): Combine AGGR_INIT_EXPR and CALL_EXPR cases. gcc/testsuite/ChangeLog: * g++.dg/coroutines/coro-bad-alloc-02-no-op-new-nt.C: Adjust diagnostic. * g++.dg/diagnostic/aggr-init1.C: New test. --- gcc/cp/error.cc | 79 +++++-------------- .../coro-bad-alloc-02-no-op-new-nt.C | 2 +- gcc/testsuite/g++.dg/diagnostic/aggr-init1.C | 36 +++++++++ 3 files changed, 55 insertions(+), 62 deletions(-) create mode 100644 gcc/testsuite/g++.dg/diagnostic/aggr-init1.C base-commit: 63b6967b06b5387821c4e5f2c113da6aaeeae2b7 diff --git a/gcc/cp/error.cc b/gcc/cp/error.cc index 8381f950488..4a60fac9694 100644 --- a/gcc/cp/error.cc +++ b/gcc/cp/error.cc @@ -84,7 +84,6 @@ static void dump_type_prefix (cxx_pretty_printer *, tree, int); static void dump_type_suffix (cxx_pretty_printer *, tree, int); static void dump_function_name (cxx_pretty_printer *, tree, int); static void dump_call_expr_args (cxx_pretty_printer *, tree, int, bool); -static void dump_aggr_init_expr_args (cxx_pretty_printer *, tree, int, bool); static void dump_expr_list (cxx_pretty_printer *, tree, int); static void dump_global_iord (cxx_pretty_printer *, tree); static void dump_parameters (cxx_pretty_printer *, tree, int); @@ -2253,46 +2252,15 @@ dump_template_parms (cxx_pretty_printer *pp, tree info, static void dump_call_expr_args (cxx_pretty_printer *pp, tree t, int flags, bool skipfirst) { - tree arg; - call_expr_arg_iterator iter; + const int len = call_expr_nargs (t); pp_cxx_left_paren (pp); - FOR_EACH_CALL_EXPR_ARG (arg, iter, t) + for (int i = skipfirst; i < len; ++i) { - if (skipfirst) - skipfirst = false; - else - { - dump_expr (pp, arg, flags | TFF_EXPR_IN_PARENS); - if (more_call_expr_args_p (&iter)) - pp_separate_with_comma (pp); - } - } - pp_cxx_right_paren (pp); -} - -/* Print out the arguments of AGGR_INIT_EXPR T as a parenthesized list - using flags FLAGS. Skip over the first argument if SKIPFIRST is - true. */ - -static void -dump_aggr_init_expr_args (cxx_pretty_printer *pp, tree t, int flags, - bool skipfirst) -{ - tree arg; - aggr_init_expr_arg_iterator iter; - - pp_cxx_left_paren (pp); - FOR_EACH_AGGR_INIT_EXPR_ARG (arg, iter, t) - { - if (skipfirst) - skipfirst = false; - else - { - dump_expr (pp, arg, flags | TFF_EXPR_IN_PARENS); - if (more_aggr_init_expr_args_p (&iter)) - pp_separate_with_comma (pp); - } + tree arg = get_nth_callarg (t, i); + dump_expr (pp, arg, flags | TFF_EXPR_IN_PARENS); + if (i + 1 < len) + pp_separate_with_comma (pp); } pp_cxx_right_paren (pp); } @@ -2451,28 +2419,9 @@ dump_expr (cxx_pretty_printer *pp, tree t, int flags) break; case AGGR_INIT_EXPR: - { - tree fn = NULL_TREE; - - if (TREE_CODE (AGGR_INIT_EXPR_FN (t)) == ADDR_EXPR) - fn = TREE_OPERAND (AGGR_INIT_EXPR_FN (t), 0); - - if (fn && TREE_CODE (fn) == FUNCTION_DECL) - { - if (DECL_CONSTRUCTOR_P (fn)) - dump_type (pp, DECL_CONTEXT (fn), flags); - else - dump_decl (pp, fn, 0); - } - else - dump_expr (pp, AGGR_INIT_EXPR_FN (t), 0); - } - dump_aggr_init_expr_args (pp, t, flags, true); - break; - case CALL_EXPR: { - tree fn = CALL_EXPR_FN (t); + tree fn = cp_get_callee (t); bool skipfirst = false; /* Deal with internal functions. */ @@ -2494,8 +2443,10 @@ dump_expr (cxx_pretty_printer *pp, tree t, int flags) && NEXT_CODE (fn) == METHOD_TYPE && call_expr_nargs (t)) { - tree ob = CALL_EXPR_ARG (t, 0); - if (TREE_CODE (ob) == ADDR_EXPR) + tree ob = get_nth_callarg (t, 0); + if (is_dummy_object (ob)) + /* Don't print dummy object. */; + else if (TREE_CODE (ob) == ADDR_EXPR) { dump_expr (pp, TREE_OPERAND (ob, 0), flags | TFF_EXPR_IN_PARENS); @@ -2514,7 +2465,13 @@ dump_expr (cxx_pretty_printer *pp, tree t, int flags) pp_string (cxx_pp, M_("")); break; } - dump_expr (pp, fn, flags | TFF_EXPR_IN_PARENS); + + if (TREE_CODE (fn) == FUNCTION_DECL + && DECL_CONSTRUCTOR_P (fn) + && is_dummy_object (get_nth_callarg (t, 0))) + dump_type (pp, DECL_CONTEXT (fn), flags); + else + dump_expr (pp, fn, flags | TFF_EXPR_IN_PARENS); dump_call_expr_args (pp, t, flags, skipfirst); } break; diff --git a/gcc/testsuite/g++.dg/coroutines/coro-bad-alloc-02-no-op-new-nt.C b/gcc/testsuite/g++.dg/coroutines/coro-bad-alloc-02-no-op-new-nt.C index 89972b60945..f375ba9473a 100644 --- a/gcc/testsuite/g++.dg/coroutines/coro-bad-alloc-02-no-op-new-nt.C +++ b/gcc/testsuite/g++.dg/coroutines/coro-bad-alloc-02-no-op-new-nt.C @@ -9,7 +9,7 @@ #include "coro1-allocators.h" struct coro1 -f () /* { dg-error {'coro1::promise_type::get_return_object_on_allocation_failure\(\)\(\)' is provided by 'std::__n4861::__coroutine_traits_impl::promise_type' \{aka 'coro1::promise_type'\} but 'operator new' is not marked 'throw\(\)' or 'noexcept'} } */ +f () /* { dg-error {'coro1::promise_type::get_return_object_on_allocation_failure\(\)' is provided by 'std::__n4861::__coroutine_traits_impl::promise_type' \{aka 'coro1::promise_type'\} but 'operator new' is not marked 'throw\(\)' or 'noexcept'} } */ { co_return; } diff --git a/gcc/testsuite/g++.dg/diagnostic/aggr-init1.C b/gcc/testsuite/g++.dg/diagnostic/aggr-init1.C new file mode 100644 index 00000000000..3c32124d6fd --- /dev/null +++ b/gcc/testsuite/g++.dg/diagnostic/aggr-init1.C @@ -0,0 +1,36 @@ +// PR c++/116634 +// { dg-do compile { target c++11 } } + +namespace std { + using size_t = decltype(sizeof(42)); +} + +class ConstString final { +public: + constexpr ConstString() noexcept: buf(), len(0) {} + template + constexpr ConstString(const char (&a)[N]): buf(a), len(N - 1) {} + constexpr ConstString(const ConstString &c1): buf(c1.buf), len(static_cast(c1.len)) {} + +private: + const char* buf; + int len; +}; + +template +struct Any final { + constexpr + Any(ConstString (&&_vec)[N]) noexcept: vec(_vec){} // { dg-error "array" } + + ConstString vec[N]; +}; + +template +constexpr static +auto Any_of(const char (&...c1)[N1]) -> Any(sizeof...(N1))> { + return {{ConstString(c1)...}}; +} + +int main() { + constexpr static const auto aa1 = Any_of("abcd", "def"); // { dg-message {"abcd", "def"} } +}