From patchwork Sat Apr 15 16:34:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 83738 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1135119vqo; Sat, 15 Apr 2023 09:36:06 -0700 (PDT) X-Google-Smtp-Source: AKy350Z4PPlBtfhYoVGQOqpRV++zkD1m6pvOmmyVhjkde7EUOZXNu9nEB5FmwNqC7mhb59iElQy8 X-Received: by 2002:a17:907:7661:b0:94e:ef3c:1d7c with SMTP id kk1-20020a170907766100b0094eef3c1d7cmr2882776ejc.75.1681576566421; Sat, 15 Apr 2023 09:36:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681576566; cv=none; d=google.com; s=arc-20160816; b=GFdb3+DU/o1iuFDfI6cc8NNWyVKQDAStUXvFRQs3GZVyIGQNXlBn6xUuaJJ0URedlg lYcOkwYY4AzuZMXRZHZrWYnN4NXd/GdFjJuUO1hucgCVQx+CObdSNViLUDPieKNrZQdm leX/NB9MTuLhBwOzTbfR2dWJhUQ/WiZ3+vQdbKAth6MXg5ssUG83hAa77djbyLi2/1sC n79ST/utp+Wf0MrdJ+Em6waTRS2UvQPKvenuzBPvMau/jzzvjLMfjoAqXzaF8zOgeUaC Twnwn1HWni42r/TnTZMzgCoECiJjrbG2THEhUUPrex7hNH6IuesGBU7ercLMWNk6GJRN xUFA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:to :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=VI+reBFz6wPiDnPkviq5tuE82V8Ra64ENcsuLReY3CY=; b=Jt8Vyh/2uxCnMHQwdna6J8OYjxijQEageMgx+T/l3br3RU0/QN+toRPDD+V4sHjqO+ VZzqQAfxr1VDeQm6RTY2HDMyqeyO581VE75r31/tRvtArFYxjC1oTceIXdeH2LKdluZ6 CFppuCBzHO6+V+Au4v4xJ3YXTh+G9pyRpagZAxZzUM1KcYFcbaCrCbmGc0aKLq44qXEk 2NXTcvCTsM7yZsHD6g593i+AXvs7GMFIcY2tBtyZo5MCgzRs6dHg/E/O74VUjwduE+Kr mj0et+VHJYjLbL0iEpARi3GZ7uu6AOgUHiKhjCY4T/4FtsGbalrPpaKxaOkqymcKwrB4 0btQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=okLCGWMZ; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id u5-20020aa7d0c5000000b0050504c50433si6691060edo.8.2023.04.15.09.36.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 15 Apr 2023 09:36:06 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=okLCGWMZ; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E9854385703E for ; Sat, 15 Apr 2023 16:35:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E9854385703E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1681576559; bh=VI+reBFz6wPiDnPkviq5tuE82V8Ra64ENcsuLReY3CY=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=okLCGWMZ3UbdxW2AnbQs40FsEJcuJ8DZuMJWUitNmm69SCwzZ1LsFnE4BZjaYpKQB RlS80jsya9Cqn5JiGH/RwKK+EglfVgUvhn5D4wheTV/8dCiTWoX93caGsbpsTDrnBq 6rLBnShUDTpTQhLWkVyrGM6LvFloNU4mAVCeZBGs= 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 ESMTPS id F1E453857724 for ; Sat, 15 Apr 2023 16:35:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org F1E453857724 Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-160-lkBYcb_JMNmz9a_UD9CzRg-1; Sat, 15 Apr 2023 12:34:54 -0400 X-MC-Unique: lkBYcb_JMNmz9a_UD9CzRg-1 Received: by mail-qk1-f198.google.com with SMTP id s6-20020a37a906000000b007468eaf866aso592670qke.17 for ; Sat, 15 Apr 2023 09:34:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681576493; x=1684168493; 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=VI+reBFz6wPiDnPkviq5tuE82V8Ra64ENcsuLReY3CY=; b=ey05U0jR8OncTOeWi2NbqaSFntHrvtYpvYs+UsPsqoTdw2F9iGtYKCkcolC+XxuxXI 3cAaVkTg5jbEN8nPwVPI2Dfv3CvyX2Rh/xFBM7HZRaYm3/7rbtxKHLK9QZR0X0pCe2RR BRi3SoXjLYnQlvOZqFeQFR0V3/+D3qBiHh27CJ1gHkbexACaMjNrko8CQrwxctNYdC24 fjBfyN0E3gUFyZtS3nMWMsgJIYMpAgdsZiJcAV5Z4nEeXjy0cVIBq5a26K//0iIZcrSE 8Mk5TbbXziEgj++8y9Cn2CGaq2p5YvX91qihpTYIZWUFRBmuz4ppDVIfJBhLL1CPBCvm 5CAw== X-Gm-Message-State: AAQBX9dwynIm1tm5+kDoaChqOudX+sL/tKNNn/7jMaH1gRF7oQsu0h1P cBCspFS6unI28jZ0O97yrBEAPbzMsomIZKc5qHr2SNa9pJGGDzohqiwJ9FOefiIAgiwzU0wkf24 rek1rgf5fVuFBnlpOpu57HOVzOnBR9tGCC90AuhCbrvD4htwffKUR+UJsXtXvBUjiz/FGDlqjcQ == X-Received: by 2002:a05:622a:1986:b0:3e4:e5bf:a24d with SMTP id u6-20020a05622a198600b003e4e5bfa24dmr14467608qtc.11.1681576493429; Sat, 15 Apr 2023 09:34:53 -0700 (PDT) X-Received: by 2002:a05:622a:1986:b0:3e4:e5bf:a24d with SMTP id u6-20020a05622a198600b003e4e5bfa24dmr14467581qtc.11.1681576493041; Sat, 15 Apr 2023 09:34:53 -0700 (PDT) Received: from jason.com ([66.31.49.15]) by smtp.gmail.com with ESMTPSA id x6-20020a05620a448600b0074852cdc4bcsm1995474qkp.62.2023.04.15.09.34.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 15 Apr 2023 09:34:52 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [pushed] c++: constexpr aggregate destruction [PR109357] Date: Sat, 15 Apr 2023 12:34:49 -0400 Message-Id: <20230415163449.3236640-1-jason@redhat.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.7 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_H2, 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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jason Merrill via Gcc-patches From: Jason Merrill Reply-To: Jason Merrill Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763260829668458045?= X-GMAIL-MSGID: =?utf-8?q?1763260829668458045?= Tested x86_64-pc-linux-gnu, applying to trunk. -- 8< -- We were assuming that the result of evaluation of TARGET_EXPR_INITIAL would always be the new value of the temporary, but that's not necessarily true when the initializer is complex (i.e. target_expr_needs_replace). In that case evaluating the initializer initializes the temporary as a side-effect. PR c++/109357 gcc/cp/ChangeLog: * constexpr.cc (cxx_eval_constant_expression) [TARGET_EXPR]: Check for complex initializer. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/constexpr-dtor15.C: New test. --- gcc/cp/constexpr.cc | 15 +++++++++++---- gcc/testsuite/g++.dg/cpp2a/constexpr-dtor15.C | 19 +++++++++++++++++++ 2 files changed, 30 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp2a/constexpr-dtor15.C base-commit: 9964df74a9e99e850bf9b0b6ff5c47133f846db8 diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc index 3de60cfd0f8..d1097764b10 100644 --- a/gcc/cp/constexpr.cc +++ b/gcc/cp/constexpr.cc @@ -7230,16 +7230,23 @@ cxx_eval_constant_expression (const constexpr_ctx *ctx, tree t, non_constant_p, overflow_p); if (*non_constant_p) break; - /* Adjust the type of the result to the type of the temporary. */ - r = adjust_temp_type (type, r); + /* If the initializer is complex, evaluate it to initialize slot. */ + bool is_complex = target_expr_needs_replace (t); + if (!is_complex) + { + r = unshare_constructor (r); + /* Adjust the type of the result to the type of the temporary. */ + r = adjust_temp_type (type, r); + ctx->global->put_value (slot, r); + } if (TARGET_EXPR_CLEANUP (t) && !CLEANUP_EH_ONLY (t)) ctx->global->cleanups->safe_push (TARGET_EXPR_CLEANUP (t)); - r = unshare_constructor (r); - ctx->global->put_value (slot, r); if (ctx->save_exprs) ctx->save_exprs->safe_push (slot); if (lval) return slot; + if (is_complex) + r = ctx->global->get_value (slot); } break; diff --git a/gcc/testsuite/g++.dg/cpp2a/constexpr-dtor15.C b/gcc/testsuite/g++.dg/cpp2a/constexpr-dtor15.C new file mode 100644 index 00000000000..d34c27eee45 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/constexpr-dtor15.C @@ -0,0 +1,19 @@ +// PR c++/109357 +// { dg-do compile { target c++20 } } +// { dg-prune-output "used but never defined" } + +struct basic_string { + char _M_local_buf; + basic_string(); + constexpr basic_string(const char *) {} + constexpr ~basic_string(); + constexpr basic_string& operator=(basic_string); +}; +struct S1 { + basic_string x; + basic_string y; +} s1; +struct s2 { + ~s2(); +}; +s2::~s2() { s1 = {"", ""}; }