From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mo4-p00-ob.smtp.rzone.de (mo4-p00-ob.smtp.rzone.de [81.169.146.220]) by sourceware.org (Postfix) with ESMTPS id 03E653857711 for ; Thu, 4 May 2023 09:45:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 03E653857711 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gjlay.de Authentication-Results: sourceware.org; spf=none smtp.mailfrom=gjlay.de ARC-Seal: i=1; a=rsa-sha256; t=1683193507; cv=none; d=strato.com; s=strato-dkim-0002; b=ews95pQn6wF+9IBbxgEA3KoxjvJnf4epqJTAdMN0b9yyo9kXoij+jUvm/lFjS/4TQm RyJW7szKvysRmb/AszlHtOnLSQ8FHl+RV9JWFzvoBHodNEvV8r0tTAOQx00oFywAM7wv BMiLVARMO/9FhnWPcG8Oxuy7qTt0P7QBYT+LTyYTMIGRpOYFyLOM8KS4eTp+YBSkIa7a fG8Wlsa+Lc7lNHSrsB9/Di2FBSd4YYv0qCaalvRUTnNpW87JHo7+O4mc5E0TVKhOYfYU s6tqaNSM5ZdyuodgUjObzIP6QY0hKFWZh/20ZuerI1jcj3HWxNg8+bZ1C9OwAykw54Fv Xsrw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; t=1683193507; s=strato-dkim-0002; d=strato.com; h=Subject:From:To:Date:Message-ID:Cc:Date:From:Subject:Sender; bh=9m6/9o4Io7ZydSeS+QiSBEtYLTha9ScKR7/eY5DmL8o=; b=TuquO7BJAarsvqkjwRvDfOgKQ0Fz8Ysz2fuexLr75L+JDBh1GwyhRfXAAPsZ2ukGn6 Xdu6YzizhaXmYRF5qdjdaOMVkYfalrtetv2H6DIwku7HrHbxpWR+9NG57WzYpwpJNLL2 Vak0GZPytY60liXdzvWbdSABGA47OpwC7zQyWb/1qYzUb2O/SDLlP+B+9B0fih8oR8Pi he/BW98QVwu8YRHbT/SjXIZcyeMZ5WYTmOfp/7H5rcTb3jewNPuhSnqheD72c4Ls2gv7 z/qXzvNc1Ejziel7++QwIfKH65g3DgMRhPW5BGEwcWhnp1h6QU15UBnRhn4lMLCMjhJc uG5Q== ARC-Authentication-Results: i=1; strato.com; arc=none; dkim=none X-RZG-CLASS-ID: mo00 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1683193507; s=strato-dkim-0002; d=gjlay.de; h=Subject:From:To:Date:Message-ID:Cc:Date:From:Subject:Sender; bh=9m6/9o4Io7ZydSeS+QiSBEtYLTha9ScKR7/eY5DmL8o=; b=NfA8bJBDbP10M6lrfKetBArniKiKV0G/R1kfD8T+Je/5hfkh9RCirCjNHYE8CyAptn sIwZZUptjuuf32ieCbQyuMX4PsyHR65fu9gAx8uH+qltPjIglZvxllAzRi2af4t1jZku O/eH0dAmTrno8SnRp0wrgcfjYD4prObU3QKkHqgVPHEV6AtOcHlnwoVB7Imfluw+1z6x JqGGW17tEUQnALNlpyXPK8aYUXqMk4L+06J9EDK7a96+7Ed5YnQZZG09zxzIzlUM9oUK 9zpCQrwgK3YO6ki6jEqawJqVdZGwM4xarNJwFzMendhe9zhw+al/IwXMFEQOhs1CFFAi tppQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; t=1683193507; s=strato-dkim-0003; d=gjlay.de; h=Subject:From:To:Date:Message-ID:Cc:Date:From:Subject:Sender; bh=9m6/9o4Io7ZydSeS+QiSBEtYLTha9ScKR7/eY5DmL8o=; b=1r3lZqi3mx5TsNdE5jDyOVzHt96WTqVXRlJRxhJCl00jX0OsrLry4RL9L3PGc/eN7E 0kzoOQB6Lh1eoQZBFHCw== X-RZG-AUTH: ":LXoWVUeid/7A29J/hMvvT3koxZnKT7Qq0xotTetVnKkRmM69o2y+LiO3MutATA==" Received: from [192.168.2.102] by smtp.strato.de (RZmta 49.4.0 DYNA|AUTH) with ESMTPSA id z691f1z449j7FKT (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate) for ; Thu, 4 May 2023 11:45:07 +0200 (CEST) Message-ID: <7a44d8e8-19aa-79f7-f018-7d976b258ac7@gjlay.de> Date: Thu, 4 May 2023 11:45:06 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.9.0 Content-Language: en-US To: gcc-help@gcc.gnu.org From: Georg-Johann Lay Subject: g++ problem with order of evaluation of arguments of delete. Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Given the following C++ code: struct Lexer; struct Token { Lexer* const lexer_; Token (Lexer *l) : lexer_(l) {} ~Token() = default; Token() = delete; Token (const Token&) = delete; Token (Token&&) = delete; void operator= (const Token&) = delete; void operator= (Token&&) = delete; }; struct Lexer { Token *token_; Lexer() = default; ~Lexer() { delete token_; } Lexer (const Lexer&) = delete; Lexer (Lexer&&) = delete; void operator= (const Lexer&) = delete; void operator= (Lexer&&) = delete; }; int main() { Lexer *lexer = new Lexer(); Token *token = new Token (lexer); lexer->token_ = token; delete token->lexer_; // delete lexer; // is OK } When I compile this with g++ v11.3 (same with g++ from master from 2023-04-20) and run $ g++ main-3.cpp -Os -W -Wall -Wextra -dumpbase "" -save-temps -dp && ./a.out Segmentation fault (core dumped) The assembly shows that the generated code does two calls to "delete" but just one call to "new", so it's clear something is going wrong. As far as I understand, the "delete token_" in ~Lexer is a sequence point, so that dereferencing token in "delete->lexer_" must be sequenced before calling ~Token ? Segmentation fault also occurs with -O0, but goes away when removing the "const" in "Lexer* const lexer_;". My question: Is this a GCC problem, or a problem with the code and sequence points? Johann