Bug 1061435

Summary: Clang exposes bug with unexpected forward-declaration of type_info
Product: Red Hat Enterprise Linux 6 Reporter: Bryan Totty <btotty>
Component: gccAssignee: Jakub Jelinek <jakub>
Status: CLOSED ERRATA QA Contact: qe-baseos-tools-bugs
Severity: low Docs Contact:
Priority: low    
Version: 6.3CC: jwakely, law, mcermak, mfranc, mpolacek, vlee
Target Milestone: rcKeywords: Reopened
Target Release: 6.6   
Hardware: All   
OS: Linux   
URL: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56468
Whiteboard:
Fixed In Version: gcc-4.4.7-5.el6 Doc Type: Bug Fix
Doc Text:
Prior this release, a program using <typeinfo> and <exception> headers would fail to compile with an "incomplete type" error message when compiled with a Clang compiler. This does not happen with G++ compiler, since it declares std::type_info implicitly. The <exception> header in libstdc++ has been adjusted and now the program compiles correctly even with the clang compiler.
Story Points: ---
Clone Of: Environment:
Last Closed: 2014-10-14 05:01:33 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 1056252    

Description Bryan Totty 2014-02-04 20:39:25 UTC
Copied from: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56468
--------------------------

The following program fails to compile with Clang++ 3.2:

#include <typeinfo>
#include <exception>

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

int main() {}

The output in the shell is:

$ 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.
$

The problem is that <typeinfo> includes <exception> before it forward-declares std::type_info. In <exception>, type_info is used in the context of std::__exception_ptr, thus Clang generates an implicit forward-declaration for std::__exception_ptr::type_info and, when used in the above code, consequently fails.

Further discussion has taken place at <http://stackoverflow.com/q/15098174>.

Comment 1 Jakub Jelinek 2014-02-10 14:08:25 UTC
Well, it is not a bug, because g++ predeclares that.
Now, you are mentioning gcc 4.7, so what exactly would you like to be changed in RHEL?  DTS 1.[01] gcc (the only 47 one we ship, or DTS 2, or system gcc (4.4-RH), something else?

Comment 2 Bryan Totty 2014-03-03 22:58:18 UTC
This was meant to be against g++ 4.4.6 on RHEL 6.3. The upstream bug description in this Red Hat bug was copied from http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56468 which is what actually defined 4.7 in the test.

Do you know if this applies to our supported g++ 4.4 version for RHEL 6? This may have only been an issue in g++ 4.7, but I am not certain.

Comment 3 Jeff Law 2014-03-13 16:35:54 UTC
Sorry, but our policy is not to fix missed-error bugs in the RHEL base compiler.  Such changes run the very real risk of code which had previously compiled with the RHEL base compiler no longer compiling.

Comment 8 Jeff Law 2014-03-13 19:15:45 UTC
Jakub & Jonathan set me stright.  I clearly misunderstood the issue here.

GCC has an implicit declaration which results in GCC accepting this code without an error.  Clang doesn't have the implicit declaration and thus complains.  The request is to fix exception_ptr.h to explicitly declare type_info which should be safe.

This BZ is _not_ a request to have GCC issue an error here.

Comment 17 errata-xmlrpc 2014-10-14 05:01:33 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

http://rhn.redhat.com/errata/RHBA-2014-1377.html

Comment 18 Dave Johansen 2014-10-31 02:59:37 UTC
*** Bug 1129899 has been marked as a duplicate of this bug. ***