From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 4D0F23858D28; Sun, 26 May 2024 12:16:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4D0F23858D28 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1716725778; bh=KxYrod2+dQdwdYs2hDJkAcNPXnng2C7dqw3sspaGzcQ=; h=From:To:Subject:Date:From; b=GGA9FU+nYp9YTLmdE9IU+3fVs+W9EDWVf3eHtoF6G6gT3nkdryUYAG6wzjoIHspd0 RnV3nFxXonFhCl0L1c1liY058Sds3na8fWufk/lsYqhBWcLz9EhT9Bno47IltbIpEP CmIUJS3lHBhejHYxgHesLq5XmoWDDiS172SU6Osw= From: "konstantin.vladimirov at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/115233] New: constexpr RVO result is not determined as constant epression Date: Sun, 26 May 2024 12:16:17 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 14.1.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: konstantin.vladimirov at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D115233 Bug ID: 115233 Summary: constexpr RVO result is not determined as constant epression Product: gcc Version: 14.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: konstantin.vladimirov at gmail dot com Target Milestone: --- Consider I have this type: --- struct Type { int a; const int& b; constexpr Type() : a(1), b(a) {} }; constexpr Type t1; constexpr int c11 =3D t1.a; constexpr int c12 =3D t1.b; --- c11 and c12 are fine for both gcc and clang Now lets introduce constexpr function which is subject to RVO: constexpr auto get() { return Type(); } Now try this: constexpr Type t2 =3D get(); constexpr int c2 =3D t2.a; This code compiles fine with clang but not with gcc. Live example on godbolt: https://godbolt.org/z/zf3YvebbG According to [expr.const] and [class.copy.elision] result of constexpr func= tion is necessary RVO and is contant expression, so t2 construction is fine and = t2.a is constant expression as well.=