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

--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Further discussion from PR 67772:

Consider:

  namespace std { struct type_info {}; }
  struct A {};
  auto x = typeid(void(A::*)() const);

Clang emits the type info as:

_ZTIM1AKFvvE:
        .quad   _ZTVN10__cxxabiv129__pointer_to_member_type_infoE+16
        .quad   _ZTSM1AKFvvE
        .long   0                       # 0x0
        .zero   4
        .quad   _ZTIKFvvE
        .quad   _ZTI1A

GCC emits it as:

_ZTIM1AKFvvE:
        .quad   _ZTVN10__cxxabiv129__pointer_to_member_type_infoE+16
        .quad   _ZTSM1AKFvvE
        .long   0
        .zero   4
        .quad   _ZTIFvvE
        .quad   _ZTI1A

It appears that Clang is correct here; the 'const' in this case is not a
qualifier, so should not be removed when forming the pointee type_info. If GCC
really did think this was a const qualifier applied to a function type, it
would be emitting the wrong flags (should be .long 1, not .long 0 in that
case).


This translates into a wrong-code bug in a case like this:

struct A;
extern "C" void puts(const char*);
int main() {
  try {
    throw (void(A::*)())0;
  } catch (void (A::*)() const) {
    puts("bad catch");
  }
}

... where GCC erroneously catches a pointer to non-const member function as a
pointer to const member function.

Reply via email to