From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2140) id DB0A2385842C; Wed, 29 Nov 2023 04:35:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DB0A2385842C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1701232516; bh=9ON0ovidl5GWCkeEDdR1EgVlJE8wnDthlPkhe0aA+YI=; h=From:To:Subject:Date:From; b=EEB4dbs1QQFWpmfNfYX0EiznW1xuGLB5ua7t3KgJsLvVha8OghFA96zQtyMChxYHK 2SQtXL5enRBRADIEBsAs5NjR8U9ihWxOYLetu7O2IRItr5mTY6/lbzEhLfDanWGaQq cAH5KffCuucAqzYA7ZeTwD2I07Q9ov4n6X6aZGtQ= 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: 7431755100be6acbb4ee4dc2134d8ecd85e54ddb X-Git-Newrev: 554f30e1af04d885fbd149561c526af572b0cbc4 Message-Id: <20231129043516.DB0A2385842C@sourceware.org> Date: Wed, 29 Nov 2023 04:35:16 +0000 (GMT) List-Id: https://gcc.gnu.org/g:554f30e1af04d885fbd149561c526af572b0cbc4 commit 554f30e1af04d885fbd149561c526af572b0cbc4 Author: Alexandre Oliva Date: Wed Nov 29 00:54:37 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)