From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id ADC713858034; Sun, 7 Mar 2021 15:27:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org ADC713858034 From: "nathan at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/99452] New: Inconsistent constinit handling Date: Sun, 07 Mar 2021 15:27:03 +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: 11.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: nathan at gcc dot gnu.org 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 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 07 Mar 2021 15:27:03 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D99452 Bug ID: 99452 Summary: Inconsistent constinit handling Product: gcc Version: 11.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: nathan at gcc dot gnu.org Target Milestone: --- constinit forces static initialization (or error). Sadly the std doesn't permit c++98-era address-constant expressions (symbol + addend). but we do accept that (probably a bug std=3Dc++20 vs std=3Dgnu++20 makes no differenc= e) But we do so inconsistently. Both x & y are initializable in this manner -- and we do emit such an initialization if the constinit is removed, regardle= ss of optimization level. But with constinit, the presence of the OR operator causes y's initializati= on to be rejected. Even though it's totally foldable. constinit long x =3D reinterpret_cast (&x) + 0; constinit long y =3D reinterpret_cast (&y) + (0|0); gcc-current/bin/g++ -c c.cc -std=3Dc++20=20=20=20=20=20=20=20=20=20 c.cc:4:16: error: =E2=80=98constinit=E2=80=99 variable =E2=80=98y=E2=80=99 = does not have a constant initializer 4 | constinit long y =3D reinterpret_cast (&y) + (0|0); | ^ c.cc:4:20: error: conversion from pointer type =E2=80=98long int*=E2=80=99 = to arithmetic type =E2=80=98long int=E2=80=99 in a constant expression 4 | constinit long y =3D reinterpret_cast (&y) + (0|0); Please note I plan an EWG paper to allow symbol+addend, as that seems a use= ful behaviour.=