From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id DDFAF3858C5F; Sun, 24 Dec 2023 16:22:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DDFAF3858C5F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1703434947; bh=1vl9C471NyjMo4ggAHqGTdtfQ9Nz33w8mBaOj1mCNKk=; h=From:To:Subject:Date:In-Reply-To:References:From; b=Dp7ml5wr5O1JxXHd4BJ9ZXkJEXh6Ic5d5Y5Bn3ROixYVqex37cvwvmIAYWiuarun8 ZK7pB1JpJZ3+IKjhfpCTV+J6TGGpzLklbjFzo4oDaJT7GsAUeTu6s1W7aV+kDawo84 0vebsxu5A3asL6AiXWWy1gRcWvyfVGsr0nuv3zGI= From: "andysem at mail dot ru" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/113099] locale without RTTI uses dynamic_cast before gcc 13.2 or has ODR violation since gcc 13.2 Date: Sun, 24 Dec 2023 16:22:26 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libstdc++ X-Bugzilla-Version: 11.4.0 X-Bugzilla-Keywords: ABI, documentation X-Bugzilla-Severity: normal X-Bugzilla-Who: andysem at mail dot ru 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=3D113099 --- Comment #11 from andysem at mail dot ru --- > I'm not sure what you mean by "the compiler is free to generate code that= takes it into account." Takes what into account? What problem does that fr= eedom cause? I mean the compiler could move (some part of) dynamic_cast to precede the c= heck for the standard facet. I.e. of something like this: template< typename _Facet > const _Facet* __try_use_facet(locale const& loc) { const size_t __i =3D _Facet::id._M_id(); const locale::facet** __facets =3D __loc._M_impl->_M_facets; const _Facet* __dyn_facet =3D __dynamic_cast< const _Facet* >(__facets[= __i]); // checks for every standard facet type if (__is_same(_Facet, ...)) return static_cast(__facets[__i]); return __dyn_facet; } >> I think, a failing dynamic_cast would not be useful as this would make >> std::use_facet unusable with -fno-rtti. > > I don't see a problem with that. If you want to use a polymorphic contain= er of facets, you need RTTI. The standard facets will work, but it doesn't = seem reasonable to expect it to work for program-defined facets. AFAIK, the standard or libstdc++ docs do not require RTTI for std::locale to function. In fact, the facet::id stuff seems to exist precisely to make RTTI optional in the implementations. Besides, the code, as it was written, seem= s to intend to work without RTTI by switching to static_cast instead of dynamic_cast. So making std::use_facet always fail would go against that intention. > And a std::use_facet that fails seems better than one that segfaults, doe= sn't it? No, not really. It still means users cannot use locale without RTTI, just f= or a different reason. > And I guess if the user's derived facet uses virtual inheritance from std= ::locale::facet, then this could break with the static_cast*> in libstdc++ today. Hmm. std::ctype non-virtually derives from std::locale::facet, so no, that would= not break. What wouldn't work is this: class my_facet : virtual public std::ctype< char > {}; my_facet const& fac =3D std::use_facet< my_facet >(loc); But this would fail in compile time with no RTTI, which *is* better than a segfault or an exception in runtime.=