public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/96356] New: RTTI for non-polymorphic typeid
@ 2020-07-28 13:45 c.de-claverie at pm dot me
  2020-07-28 14:32 ` [Bug c++/96356] " redi at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: c.de-claverie at pm dot me @ 2020-07-28 13:45 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96356

            Bug ID: 96356
           Summary: RTTI for non-polymorphic typeid
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: c.de-claverie at pm dot me
  Target Milestone: ---

Hello,

I would like to bring the following possible issue to your attention to make
sure the behaviour is expected :
https://stackoverflow.com/questions/63132693

To sum up the problem, a "cannot use 'typeid' with '-fno-rtti'" error is thrown
when using the typeid operator on type-erased non-polymorphic types. It is
unclear to me whether this is the an expected behabiour or not, because the
typeid operator is resolved at compile time (according to cppreference) and, as
a result, should not be reliant on rtti.

This is my first contribution here. Please feel free to let me know if I can
add any useful information.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c++/96356] RTTI for non-polymorphic typeid
  2020-07-28 13:45 [Bug c++/96356] New: RTTI for non-polymorphic typeid c.de-claverie at pm dot me
@ 2020-07-28 14:32 ` redi at gcc dot gnu.org
  2020-07-28 14:50 ` redi at gcc dot gnu.org
  2020-07-28 15:03 ` jakub at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: redi at gcc dot gnu.org @ 2020-07-28 14:32 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96356

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Yes it's expected. The typeid operator has to return a std::typeinfo object. If
you disable generation of std::typeinfo objects, what is it supposed to return?

The savings from -fno-rtti come from not generating all the RTTI objects, not
just from refusing to use that info at runtime.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c++/96356] RTTI for non-polymorphic typeid
  2020-07-28 13:45 [Bug c++/96356] New: RTTI for non-polymorphic typeid c.de-claverie at pm dot me
  2020-07-28 14:32 ` [Bug c++/96356] " redi at gcc dot gnu.org
@ 2020-07-28 14:50 ` redi at gcc dot gnu.org
  2020-07-28 15:03 ` jakub at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: redi at gcc dot gnu.org @ 2020-07-28 14:50 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96356

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |INVALID

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
It would be theoretically possible for the compiler to elide some RTTI code
when the effects are known at compile time, e.g. so typeid(int)==typeid(int) is
always true, and typeid(int)==typeid(long) is always false, even without RTTI.

But that isn't going to help your case, where std::any::type<T>() still has to
return something, and unless the creation of the std::any and the call to
type<T>() are both visible to the compiler and inlined, then you're not going
to get something equivalent to typeid(A)==typeid(B) where the types are known
at compile time.

Such an optimisation seems likely to only work in "embarrassingly simple" cases
where you don't actually need to use typeid anyway. If it doesn't work in
actually useful cases (where the types aren't known in advance because the
types depend on run time conditions) then implementing that optimisation seems
like a waste of time.  No sensible code is going to use typeid when all the
types are known at compile time, because you wouldn't bother using type erasure
or RTTI in such cases.

Not a bug.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c++/96356] RTTI for non-polymorphic typeid
  2020-07-28 13:45 [Bug c++/96356] New: RTTI for non-polymorphic typeid c.de-claverie at pm dot me
  2020-07-28 14:32 ` [Bug c++/96356] " redi at gcc dot gnu.org
  2020-07-28 14:50 ` redi at gcc dot gnu.org
@ 2020-07-28 15:03 ` jakub at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: jakub at gcc dot gnu.org @ 2020-07-28 15:03 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96356

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org

--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
>From optimization POV (if we don't do that already), it would be nice to
optimize away after IPA comparisons the typeinfo comparisons, by making the
_ZT* symbols special (add some attribute them or whatever) and teaching the
middle-end the rules for those.

bool
foo ()
{
  return typeid (int) == typeid (long);
}

struct A { A (); virtual ~A (); };
struct B : public A {};

static inline bool
bar (A *p)
{
  return typeid (*p) == typeid (A);
}

bool
baz ()
{
  A a;
  return bar (&a);
}

bool
qux ()
{
  B a;
  return bar (&a);
}

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-07-28 15:03 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-28 13:45 [Bug c++/96356] New: RTTI for non-polymorphic typeid c.de-claverie at pm dot me
2020-07-28 14:32 ` [Bug c++/96356] " redi at gcc dot gnu.org
2020-07-28 14:50 ` redi at gcc dot gnu.org
2020-07-28 15:03 ` jakub at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).