This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: [c++] builtin functions and namespaces


> Really?  I thought this was one of those odd things in the standard
> where you could put an extern "C" function in a namespace, and it
> semantically was there, but if you actually had two such functions you
> got undefined behavior.

7.5p6 says

# At most one function with a particular name can have C language
# linkage. Two declarations for a function with C language linkage
# with the same function name (ignoring the namespace names that
# qualify it) that appear in different namespace scopes refer to the
# same function. Two declarations for an object with C language
# linkage with the same name (ignoring the namespace names that
# qualify it) that appear in different namespace scopes refer to the
# same object.

So multiple *declarations* of an extern "C" function in different
namespaces are fine; they all declare the same function.

The note following this text says that two *definitions* of such a
function are a violation of the ODR. 3.2p1 says that violations of the
ODR in a single translation unit must be diagnosed; 3.2p3 says that
violations of the ODR across translation units need not to be
diagnosed - i.e. you'd get undefined behaviour.

Regards,
Martin

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]