From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id D42463858CDB; Sat, 20 Jul 2024 05:26:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D42463858CDB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1721453183; bh=CvaJZoZFfMlHXzXhkw6vn5vbjsdZhfHg/T77SymF/FU=; h=From:To:Subject:Date:In-Reply-To:References:From; b=fpsbEfN3kWB+aGrAOgnfvGShCOqw35vO2cyEF3j+kJm1w63qzBrMrqSOro0fGXZmW AVku9cbcyxNFw4P5byo0T3/vBTVu/iTWOVgXkPOJBNBIrVtIHTJ6RIzeVTsbzNvQP4 RhjGDKoNvQjtVpGp+sDiY51URcfJCRBtHcx9YPME= From: "pinskia at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/116011] Bogus template redefinition error between pointer-to-member &T::x versus pointer &(T::x) Date: Sat, 20 Jul 2024 05:26:23 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 15.0 X-Bugzilla-Keywords: rejects-valid X-Bugzilla-Severity: normal X-Bugzilla-Who: pinskia 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: Message-ID: In-Reply-To: References: 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=3D116011 --- Comment #1 from Andrew Pinski --- Clang also rejects this: ``` :13:55: error: no matching function for call to 'f' 13 | constexpr int g(char (*p)[sizeof(char)] =3D 0) { return f(p); } | ^~~~ :8:15: note: candidate function template not viable: no known conversion from 'char (*)[1]' to 'char (*)[2]' for 1st argument 8 | constexpr int f(char (*)[sizeof(q(&T::x))]) { return 1; } | ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~ :11:15: note: candidate function template not viable: no known conversion from 'char (*)[1]' to 'char (*)[2]' for 1st argument 11 | constexpr int f(char (*)[sizeof(q(&(T::x)))]) { return 2; } | ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ :16:15: error: static assertion expression is not an integral const= ant expression 16 | static_assert(g() =3D=3D 2); | ^~~~~~~~ ``` MSVC rejects it the same way as GCC: ``` (11): error C2995: 'int f(char (*)[])': function template has alrea= dy been defined (8): note: see declaration of 'f' (13): error C3615: constexpr function 'g' cannot result in a consta= nt expression (13): note: failure was caused by control reaching the end of a constexpr function (14): error C3615: constexpr function 'h' cannot result in a consta= nt expression (14): note: failure was caused by control reaching the end of a constexpr function (16): error C2131: expression did not evaluate to a constant (16): note: function violates 'constexpr' rules or has errors (16): note: see usage of 'g' (16): note: the call stack of the evaluation (the oldest call first= ) is (16): note: while evaluating function 'int g(char (*)[1])' (17): error C2131: expression did not evaluate to a constant (17): note: function violates 'constexpr' rules or has errors (17): note: see usage of 'h' (17): note: the call stack of the evaluation (the oldest call first= ) is (17): note: while evaluating function 'int h(char (*)[2])' ``` EDG is also rejects it the same way as GCC: ``` "", line 11: error: function template "f" has already been defined (previous definition at line 7) constexpr int f(char (*)[sizeof(q(&(T::x)))]) { return 2; } ^ "", line 13: error: no instance of function template "f" matches the argument list argument types are: (char (*)[1]) constexpr int g(char (*p)[sizeof(char)] =3D 0) { return f(p); } ^ "", line 8: note: function template "f" does not match because argu= ment #1 does not match parameter constexpr int f(char (*)[sizeof(q(&T::x))]) { return 1; } ^ "", line 17: error: static assertion failed static_assert(h() =3D=3D 1); ^ ```=