From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 5DBF93858D1E; Wed, 30 Nov 2022 19:32:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5DBF93858D1E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1669836750; bh=a6KXp3ipzv3aQFIbGBLfWmgxocdeHpaluDCH9MXV6dk=; h=From:To:Subject:Date:From; b=WLgk6cmfx4oGYIbZsXJHjHF/PsKAt5DeIDFk/7SXUe2KzD1YUNKiFZxZ7mnyuvf0l YyRRnN65P8t+2O1iGKENQVY4zuVwSdLJfLxNfyxb1Ch/aYA2rT5p3gGyGxr2l/xppz oSBFR0O6Ge+z32X9rDvk4D77vhn3a/lI20PNNCM0= From: "johelegp at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/107939] New: Rejects use of `extern const` variable in a template Date: Wed, 30 Nov 2022 19:32:30 +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: 13.0 X-Bugzilla-Keywords: rejects-valid X-Bugzilla-Severity: normal X-Bugzilla-Who: johelegp 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 keywords bug_severity priority component assigned_to reporter cc 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=3D107939 Bug ID: 107939 Summary: Rejects use of `extern const` variable in a template Product: gcc Version: 13.0 Status: UNCONFIRMED Keywords: rejects-valid Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: johelegp at gmail dot com CC: johelegp at gmail dot com Target Milestone: --- See https://compiler-explorer.com/z/q3a7e7s1e. Changing `#if 1` to `#if 0` works, so this can't be due to > The program is ill-formed, no diagnostic required, if: > (6.4) a hypothetical instantiation of a template immediately following it= s definition would be ill-formed due to a construct that does not depend on= a template parameter, or > -- https://eel.is/c++draft/temp.res.general#6.4 And since all compilers accept it as a non-template, nothing in [expr.const= ] is being violated. ```C++ struct Q { struct P { const Q* p; }; int n; constexpr P operator()(auto) const { return {this}; } }; extern const Q q; #if 1 template constexpr auto p =3D q(0); static_assert(p<0>.p =3D=3D &q); #else constexpr auto p =3D q(0); static_assert(p.p =3D=3D &q); #endif constexpr Q q =3D {}; ``` ``` :12:37: error: the value of 'q' is not usable in a constant express= ion 12 | template constexpr auto p =3D q(0); | ^ :9:16: note: 'q' was not declared 'constexpr' 9 | extern const Q q; | ^ :13:22: error: non-constant condition for static assertion 13 | static_assert(p<0>.p =3D=3D &q); | ~~~~~~~^~~~~ Compiler returned: 1 ```=