Bug 19092 - [DR 561] template code does not ignore static functions overloads
[DR 561] template code does not ignore static functions overloads
Status: RESOLVED INVALID
Product: gcc
Classification: Unclassified
Component: c++
3.4.2
: P2 normal
: ---
Assigned To: Jason Merrill
: accepts-invalid, rejects-valid, wrong-code
: 23542 24977 29165 33129 (view as bug list)
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2004-12-20 18:31 UTC by bagnara
Modified: 2009-11-04 16:05 UTC (History)
7 users (show)

See Also:
Host: i686-pc-linux-gnu
Target:
Build:
Known to work:
Known to fail: 2.95.3 3.2.3 3.3.1 3.3.4 3.4.3 4.0.0
Last reconfirmed: 2006-02-20 18:42:11


Attachments
Small program that allows to reproduce the problem (141 bytes, text/plain)
2004-12-20 18:32 UTC, bagnara
Details

Note You need to log in before you can comment on or make changes to this bug.
Description bagnara 2004-12-20 18:31:29 UTC
The attached snippet should not compile, since foo() has internal linkage.
Instead, g++ compiles it happily and without a warning even when given
-Wall -W -pedantic.
Comment 1 bagnara 2004-12-20 18:32:29 UTC
Created attachment 7784 [details]
Small program that allows to reproduce the problem
Comment 2 Andrew Pinski 2004-12-20 18:50:01 UTC
Confirmed.
Comment 3 Wolfgang Bangerth 2004-12-20 20:43:11 UTC
Indeed. It seems as if I am not the only one who wasn't aware of the 
restriction that dependent function calls can only be to functions with 
external linkage. 
 
This should be low priority, since we only accept invalid code. 
 
W. 
Comment 4 Wolfgang Bangerth 2004-12-20 21:30:47 UTC
Actually, we can make this a rejects-valid like so: 
---------------------- 
namespace NS1 { 
  struct X {}; 
  void foo(X); 
} 
 
namespace NS2 { 
  static void foo(NS1::X); 
   
  template <typename T> 
  void bar() { 
    foo(T()); 
  } 
} 
 
template void NS2::bar<NS1::X> (); 
----------------------- 
Since NS2::foo is static, it isn't an eligible overload, so NS1::foo 
should be called. However, gcc doesn't realize this: 
 
g/x> c++ x.cc ; ./a.out ; echo $? 
x.cc: In function `void NS2::bar() [with T = NS1::X]': 
x.cc:15:   instantiated from here 
x.cc:11: error: call of overloaded `foo(NS1::X)' is ambiguous 
x.cc:7: error: candidates are: void NS2::foo(NS1::X) 
x.cc:3: error:                 void NS1::foo(NS1::X) 
 
This fails with all versions of gcc I have. 
 
W. 
Comment 5 Jonathan Wakely 2005-07-07 00:25:28 UTC
Keywords should include "wrong-code", this program should return 0:

static int f(int i)
{
    return 1;
}

int f(long l)
{
    return 0;
}

template <typename T>
    int g(T t)
    {
       return f(t);
    }

int main()
{
   return g(0);
}
Comment 6 Andrew Pinski 2005-08-24 11:44:03 UTC
*** Bug 23542 has been marked as a duplicate of this bug. ***
Comment 7 Andrew Pinski 2005-11-21 18:20:11 UTC
*** Bug 24977 has been marked as a duplicate of this bug. ***
Comment 8 Andrew Pinski 2006-09-21 14:37:10 UTC
*** Bug 29165 has been marked as a duplicate of this bug. ***
Comment 9 Andrew Pinski 2006-09-21 14:37:56 UTC
http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#561

Suspending since that Defect Report is still open.
Comment 10 Wolfgang Bangerth 2007-09-08 15:33:26 UTC
*** Bug 33129 has been marked as a duplicate of this bug. ***
Comment 11 Jason Merrill 2009-03-03 22:07:17 UTC
I'm supposed to be drafting this issue.  It is not likely to be a bug under the eventual resolution.
Comment 12 Jason Merrill 2009-11-04 16:05:18 UTC
My drafting to ratify the G++ behavior was adopted at the Santa Cruz meeting, so this is not a bug.