From: Ilya Sokolov on
Daniel Kr�gler wrote:
> specification in [lib.support.start.term]/3 (C++03) or
> [support.start.term]/4 (C++0x working draft N3090):
>
> extern "C" int atexit(void (*f)(void));
> extern "C++" int atexit(void (*f)(void));

Is it well-formed? I'm asking because 7.5/5 in n3092 states

<quote>
If two declarations declare functions with the same name
and parameter-type-list (8.3.5) to be members of the same
namespace or declare objects with the same name to be
members of the same namespace and the declarations give
the names different language linkages, the program is
ill-formed; no diagnostic is required if the declarations
appear in different translation units. ...
</quote>

but this case is not mentioned in 13.1/2 as declarations that
cannot be overloaded.


--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: Pete Becker on
Ilya Sokolov wrote:
> Daniel Kr�gler wrote:
>> specification in [lib.support.start.term]/3 (C++03) or
>> [support.start.term]/4 (C++0x working draft N3090):
>>
>> extern "C" int atexit(void (*f)(void));
>> extern "C++" int atexit(void (*f)(void));
>
> Is it well-formed? I'm asking because 7.5/5 in n3092 states
>
> <quote>
> If two declarations declare functions with the same name
> and parameter-type-list (8.3.5) to be members of the same
> namespace or declare objects with the same name to be
> members of the same namespace and the declarations give
> the names different language linkages, the program is
> ill-formed; no diagnostic is required if the declarations
> appear in different translation units. ...
> </quote>
>
> but this case is not mentioned in 13.1/2 as declarations that
> cannot be overloaded.
>

The two functions have different parameter lists, despite their being
written the same way.

--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of
"The Standard C++ Library Extensions: a Tutorial and Reference"
(www.petebecker.com/tr1book)


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: Daniel Krügler on
On 16 Apr., 00:30, Ilya Sokolov <ilyaso...(a)gmail.com> wrote:
> Daniel Kr�gler wrote:
> > specification in [lib.support.start.term]/3 (C++03) or
> > [support.start.term]/4 (C++0x working draft N3090):
>
> > extern "C" int atexit(void (*f)(void));
> > extern "C++" int atexit(void (*f)(void));
>
> Is it well-formed? I'm asking because 7.5/5 in n3092 states

It is well-formed, see below.

> <quote>
> If two declarations declare functions with the same name
> and parameter-type-list (8.3.5) to be members of the same
> namespace or declare objects with the same name to be
> members of the same namespace and the declarations give
> the names different language linkages, the program is
> ill-formed; no diagnostic is required if the declarations
> appear in different translation units. ...
> </quote>
>
> but this case is not mentioned in 13.1/2 as declarations that
> cannot be overloaded.

These conclusions are based on a wrong premise: According to
[dcl.link]/1:

"[..] Two function types with different language linkages are
distinct types even if they are otherwise identical."

This means that the parameter-type-lists are different
for both atexit functions and this allows for overloading
them. In particular, the none of the special cases listed
in subclause [over.load] is relevant here.

The tricky point is that according to [dcl.link]/4 the
declaration of the first form has a parameter which is a
pointer to a function of C language linkage and the second
form has a parameter which is a pointer to a function of
C++ language linkage.

P.8 of the same subclause also adds the note:

"[ Note: because the language linkage is part of a function
type, when a pointer to C function (for example) is
dereferenced, the function to which it refers is considered
a C function. �end note ]"

which describes the inverse effect of dereferencing a
pointer of some language linkage.

Further constraints exist, e.g. according to p. 6:

"At most one function with a particular name can have C
language linkage. [..]"

but this requirement is satisfied for the discussed
declaration pair.

HTH & Greetings from Bremen,

Daniel Kr�gler


--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]