From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2140) id 930B23858D39; Sun, 19 Nov 2023 04:44:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 930B23858D39 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1700369058; bh=2kEOBiZTPBYaNZ8nGh12WL+04EJxGNsMs/1FHKWcFkg=; h=From:To:Subject:Date:From; b=kVzPd8UrWqsNqJgb3aq1Z37A2N/1GrDsrsEuauaxYihxyVjeoePBbSNzOQf6Geb9g HJu5nX3+GGPy+T90AecybgDww1tT92lza7EjDInf4sZBm/ldQAYa+7qGKYB3e7iqhT JVPqMQf8xdaL3m6jGsBfSgkvOIFPhkoS7DSqnGZI= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Alexandre Oliva To: gcc-cvs@gcc.gnu.org Subject: [gcc(refs/users/aoliva/heads/testme)] c++: for contracts, cdtors never return this X-Act-Checkin: gcc X-Git-Author: Alexandre Oliva X-Git-Refname: refs/users/aoliva/heads/testme X-Git-Oldrev: e1357d7b9682f04ff27906e9d0a11026a55382d8 X-Git-Newrev: a7eceed38cf99e793da0395180f564999cf96f21 Message-Id: <20231119044418.930B23858D39@sourceware.org> Date: Sun, 19 Nov 2023 04:44:18 +0000 (GMT) List-Id: https://gcc.gnu.org/g:a7eceed38cf99e793da0395180f564999cf96f21 commit a7eceed38cf99e793da0395180f564999cf96f21 Author: Alexandre Oliva Date: Sat Nov 18 02:11:24 2023 -0300 c++: for contracts, cdtors never return this When targetm.cxx.cdtor_return_this() holds, cdtors have a non-VOID_TYPE_P result, but IMHO this ABI implementation detail shouldn't leak to the abstract language conceptual framework, in which cdtors don't have return values. For contracts, specifically those that establish postconditions on results, such a leakage is present, and the present patch puts an end to it: with it, cdtors get an error for result postconditions regardless of the ABI. This fixes g++.dg/contracts/contracts-ctor-dtor2.C on arm-eabi. for gcc/cp/ChangeLog * contracts.cc (check_postcondition_result): Cope with cdtor_return_this. Diff: --- gcc/cp/contracts.cc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/gcc/cp/contracts.cc b/gcc/cp/contracts.cc index 66d2298a9bf..035ca4827e7 100644 --- a/gcc/cp/contracts.cc +++ b/gcc/cp/contracts.cc @@ -636,7 +636,11 @@ make_postcondition_variable (cp_expr id) bool check_postcondition_result (tree decl, tree type, location_t loc) { - if (VOID_TYPE_P (type)) + /* Do not be confused by targetm.cxx.cdtor_return_this (); + conceptually, cdtors have no return value. */ + if (VOID_TYPE_P (type) + || DECL_CONSTRUCTOR_P (decl) + || DECL_DESTRUCTOR_P (decl)) { error_at (loc, DECL_CONSTRUCTOR_P (decl)