From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 95C483858415; Thu, 5 Aug 2021 18:09:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 95C483858415 From: "jakub at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/86369] constexpr const char* comparison fails Date: Thu, 05 Aug 2021 18:09:16 +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: 8.1.0 X-Bugzilla-Keywords: accepts-invalid X-Bugzilla-Severity: normal X-Bugzilla-Who: jakub at gcc dot gnu.org X-Bugzilla-Status: NEW 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 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: Thu, 05 Aug 2021 18:09:16 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D86369 --- Comment #6 from Jakub Jelinek --- Another possibility would be to detect it in cxx_eval_binary_expression bef= ore calling fold_binary_loc and punt. But, the constant evaluation actually doesn't track whether it is the same = or different evaluation of the same string literal, so not optimizing it would= on the other side mean we'd reject valid code. Consider constexpr auto name3(const char *p) { return p; } int main() { constexpr auto p1 =3D "test3"; constexpr auto p2 =3D "test4"; constexpr auto b1 =3D (name3(p1) =3D=3D name3(p1)); // should be true constexpr auto b2 =3D (name3(p1) =3D=3D name3(p2)); // should be false } Note, latest clang++ seems to accept b1 in both #c0 and #c6 testcases and reject b2 in both.=