From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id D45E93840C23; Mon, 25 Jan 2021 11:02:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D45E93840C23 From: "davveston at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/98820] New: Placeholder (auto) non-type template parameter wrongly deduced to 'const' for class type arguments Date: Mon, 25 Jan 2021 11:02:31 +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: davveston 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 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: Mon, 25 Jan 2021 11:02:31 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D98820 Bug ID: 98820 Summary: Placeholder (auto) non-type template parameter wrongly deduced to 'const' for class type arguments Product: gcc Version: 11.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: davveston at gmail dot com Target Milestone: --- As per [temp.param]/6 in N4861, for non-template parameters (including a ty= pe that contains a placeholder type): "[...] The top-level cv-qualifiers on the template-parameter are ignored wh= en determining its type." and as per [dcl.type.decltype]/1.2: "For an expression E, the type denoted by decltype(E) is defined as follows= :=20 - [...] naming a non-type template-parameter, decltype(E) is the type of the template-parameter after performing any necessary type deduction [...]" Thus, the following example should arguably be well-formed: #include struct A{}; template =20 void f() {=20 static_assert(std::is_same_v); } template =20 void g() {=20 static_assert(std::is_same_v); } int main() { constexpr A a{}; f(); g(); } However GCC rejects it as `decltype(a)` resolves to `A const` rather than `= A`. --- We may note that: 1) Clang accepts the program, and=20 2) Both Clang and GCC accepts the program when using a structural type dire= ctly instead of a placeholder type for the non-type template parameter; replacing the definitions of `f` and `g` above with: template =20 void f() {=20 static_assert(std::is_same_v); } template =20 void g() {=20 static_assert(std::is_same_v); } 3) Both clang and GCC accepts the program when using a placeholder type but with a non-class type as template argument to it; replacing the definitions= of `f` and `g` above with: template =20 void f() {=20 static_assert(std::is_same_v); } template =20 void g() {=20 static_assert(std::is_same_v); } and calling them as f<0>() and g<0>(); --- These standard rules are arguably somewhat confusing given that the template parameter object itself (associated with the class-type non-type template parameter) is `const` ([temp.param]/8).=