Clang rejects type_info as incomplete, although <typeinfo> is included

I lost why Klang rejects the following code:

#include <typeinfo>
#include <exception>

const char* get_name( const std::exception_ptr eptr )
{
  return eptr.__cxa_exception_type()->name();
}

int main() {}

OK with GCC, but Klang complains about type_infobeing an incomplete type:

$ g++-4.7 -std=c++0x -O3 -Wall -Wextra t.cc -o t
$ clang++-3.2 -std=c++0x -O3 -Wall -Wextra t.cc -o t
t.cc:6:37: error: member access into incomplete type 'const class type_info'
  return eptr.__cxa_exception_type()->name();
                                    ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/4.7/../../../../include/c++/4.7/bits/exception_ptr.h:144:19: note: forward declaration of
      'std::__exception_ptr::type_info'
      const class type_info*
                  ^
1 error generated.
$ 

Question: How to fix this with Clang? Or am I missing something and Klang is right to reject the code?

+5
source share
1 answer

Thanks to the comment by @HowardHinnant, I was able to fix this problem. The problem became apparent in the output of the preprocessor: libstdC ++ turns on <exception>from <type_info>before it even declares std::type_info. This led Klang to accept the new declaration forward std::__exception_ptr::type_info. The solution is as simple as illegal:

namespace std { class type_info; }

#include <typeinfo>
#include <exception>

const char* get_name( const std::exception_ptr eptr )
{
  return eptr.__cxa_exception_type()->name();
}

int main() {}

, , libstd++ , , .

UPDATE: # 56468 ​​ GCC 4.7.3 +

+4

All Articles