[patch] Fix pr16247

Richard Smith richard at metafoo.co.uk
Mon Jun 17 11:26:10 PDT 2013


On Mon, Jun 17, 2013 at 11:13 AM, Douglas Gregor <dgregor at apple.com> wrote:
>
> On Jun 17, 2013, at 11:02 AM, Richard Smith <richard at metafoo.co.uk> wrote:
>
> On Mon, Jun 17, 2013 at 9:21 AM, Douglas Gregor <dgregor at apple.com> wrote:
>
>
> On Jun 11, 2013, at 6:02 AM, Rafael Espíndola <rafael.espindola at gmail.com>
> wrote:
>
> On 10 June 2013 19:08, Rafael Espíndola <rafael.espindola at gmail.com> wrote:
>
> Richard pointed out on IRC that the patch should look at the
> redeclaration context to avoid problems with one of the functions
> being in a extern "C++". Implementing that found some interesting
> problems. Consider
>
> extern "C" {
> static void foo(int x);
> static void foo() {
> }
> void foo(int x) {
> }
> }
>
> This should be valid, since both functions have internal linkage and
> therefore none of them has C language linkage. Commenting the first
> declaration makes the code invalid as now the last one is extern C and
> [dcl.link] p6 kicks in. This means we have to do "normal" overload
> resolution first to see if the last decl we are looking at has C
> language linkage or not.
>
>
> BTW, is this sufficient evidence that we should just give static
> functions C language linkage? I just checked http://gcc.godbolt.org/
> and gcc 4.8 and icc 13 (which is edg based, no?), reject
>
> extern "C" {
> static void foo() {
> }
> static void foo(int x) {
> }
> }
>
> We are putting quiet a bit of effort to make sure we accept it and I
> still can't see the value.
>
>
> I, too, find this behavior strange. Changing between static and non-static
> shouldn’t affect whether a function can be overloaded; it’s completely
> non-intuitive and apparently at odds with existing practice in GCC/EDG.
>
>
> The latter, at least, is not the case; EDG accepts this code in both
> its compliant mode and in its g++-compatible mode. I'm surprised that
> ICC rejects this.
>
>
> Ah, interesting. Might be one of the many compatibility knobs that EDG
> provides.
>
> The former makes some degree of sense to me -- a
> 'static' declaration doesn't have external linkage and thus doesn't
> have C linkage -- although I agree that it's weird.
>
>
> So existing practice is mixed, with a bias toward rejecting the code above
> (apparently, MSVC also rejects the code in question). The standard is clear
> that the code is well-formed, but we find that result to be weird. This is
> starting to feel like a case where we badger the committee into fixing the
> standard :)

The committee have been badgered about this before; this was core issue 4:

  http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#4

I'm not sure that anything relevant has changed since, other than gcc
and MSVC not implementing that DR in the 12 intervening years. I'm
also not clear on what we would gain by changing this in the standard.




More information about the cfe-commits mailing list