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

            Bug ID: 84147
           Summary: RTTI for base class in anonymous namespace could be
                    avoided
           Product: gcc
           Version: 8.0.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: antoshkka at gmail dot com
  Target Milestone: ---

Consider the example

namespace {
struct base {
    virtual int foo() noexcept {return 1;}
};
}

struct derived1 final : base {};
struct derived2 final : base {};

struct pair {
    derived1 d1;
    derived2 d2;
};

pair test() {
    return {};
}


`base` is in the anonymous namespace (has internal linkage) and used only for
providing some functions to derived classes. There are no complex inheritances,
there are no dynamic_casts and typeid(base) calls.

RTTI for base class seems useless in that case, but it is still generated in
the assembly:


  .type typeinfo for (anonymous namespace)::base, @object
  .size typeinfo for (anonymous namespace)::base, 16
typeinfo for (anonymous namespace)::base:
  .quad vtable for __cxxabiv1::__class_type_info+16
  .quad typeinfo name for (anonymous namespace)::base
  .align 16
  .type typeinfo name for (anonymous namespace)::base, @object
  .size typeinfo name for (anonymous namespace)::base, 23
typeinfo name for (anonymous namespace)::base:
  .string "*N12_GLOBAL__N_14baseE"

Reply via email to