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.
Created attachment 7784 [details] Small program that allows to reproduce the problem
Confirmed.
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.
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.
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); }
*** Bug 23542 has been marked as a duplicate of this bug. ***
*** Bug 24977 has been marked as a duplicate of this bug. ***
*** Bug 29165 has been marked as a duplicate of this bug. ***
http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#561 Suspending since that Defect Report is still open.
*** Bug 33129 has been marked as a duplicate of this bug. ***
I'm supposed to be drafting this issue. It is not likely to be a bug under the eventual resolution.
My drafting to ratify the G++ behavior was adopted at the Santa Cruz meeting, so this is not a bug.