G++ compiler does not issue any error on the standard-violating code listed below, regardless of pedantry level. namespace A { extern "C" void foo() throw(); } extern "C" void foo(); Details ------- According to the C++ Standard, "two declarations for a function with C language linkage with the same function name... that appear in different namespace scopes refer to the same function" [7.5/6] Next, "if any declaration of a function has an exception-specification, all declarations, including the definition.., of that function shell have an exception-specification with the same set of type-ids" [15.4/2] In our example, two declarations of the same extern "C" routine 'foo' have different exception-specifications. This is the C++ standard violation. However, G++ compiler silently compiles this code. This makes to think extern "C" routine in different namespaces is not the same entity for g++.
Confirmed. The compiler treats the two declarations as the same function, though. This is evidenced by this program: --------------------- namespace A { extern "C" void foo() throw(); void f() { foo(); } } extern "C" void foo(); void f() { foo(); } --------------------- Both versions of f() should call the same function foo, and they indeed do if one looks at the assembler output. W.
ICC 6.0 rejects this.
Created attachment 15871 [details] first attempt at trying to fix the bug This patch checks that re-declaration of extern "C" functions complies with the exception specification constraints.
Created attachment 15876 [details] display warnings instead of error Second opus of the patch. It appears that the patch makes g++ not capable of compiling libstdc++ precisely because libstdc++ contains re-declarations of functions with C linkage specification, without respecting the exception specification constraints. Therefore, the we now report warnings instead of errors. Errors can be triggered using -pedantic though. The patch has been regtested on x86.
Created attachment 15911 [details] update the patch This patch looks better. It should regtest safely and is not far from behing ready to be submitted to the list.
Created attachment 15916 [details] more work in the matter This patch performs a more accurate lookup of the extern C functions to be able to emit pedwarnings on redeclarations that don't comply with exception specification constraints.
Subject: Bug 13699 Author: dodji Date: Wed Jul 16 23:44:02 2008 New Revision: 137904 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=137904 Log: 2008-07-16 Dodji Seketeli <dseketel@redhat.com> PR c++/13699 * gcc/cp/name-lookup.c (lookup_extern_c_fun_binding_in_all_ns): New function. (pushdecl_maybe_friend): Check if a redeclaration of extern C function complies with exception specification constraints. Added: trunk/gcc/testsuite/g++.dg/lookup/extern-c-redecl.C Modified: trunk/gcc/cp/ChangeLog trunk/gcc/cp/name-lookup.c trunk/gcc/testsuite/ChangeLog
fixed in trunk.