[patch] Fix pr16247

Douglas Gregor dgregor at apple.com
Mon Jun 17 09:21:38 PDT 2013


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. 

	- Doug

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130617/bde09783/attachment.html>


More information about the cfe-commits mailing list