This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: koenig lookup in C++
- To: Geoff Keating <geoffk at cygnus dot com>
- Subject: Re: koenig lookup in C++
- From: Theodore Papadopoulo <Theodore dot Papadopoulo at sophia dot inria dot fr>
- Date: Wed, 16 Aug 2000 20:52:35 +0200
- cc: gcc at gcc dot gnu dot org, jason at cygnus dot com, mark at codesourcery dot com
> Consider this testcase:
>
> namespace N1 {
> struct A { };
> void g(void (*)(A, A)) {}
> }
>
> template <class T>
> void f2(N1::A, T) {}
>
> void g(void (*)(int)) {}
>
> int main() {
> g(f2); // Works?
> }
>
> t.cc: In function `int main ()':
> t.cc:12: no matches converting function `f2' to type `void (*) (int)'
> t.cc:7: candidates are: template <class T> void f2 (N1::A, T)
>
> Should it work?
Well, as I said I'm not a langage lawyer...
I'm sure that if you write it:
namespace N1 {
struct A { };
void g(void (*)(A, A)) {}
}
template <class T>
void f2(N1::A, T) {}
void g(void (*)(int)) {}
int main() {
g(f2<N1::A>); // Works? // The change is here.
}
Then, it works. But then, if you write it as:
namespace N1 {
struct A { };
void g(void (*)(A, int)) {} // Changed here
}
template <class T>
void f2(N1::A, T) {}
void g(void (*)(int)) {}
int main() {
g(f2<int>); // Works? // And here.
}
then it should not because the template-id rule only adds the
namespace into which f2 is defined (in this case ::) plus the namespaces of the
template arguments (in this case int thus nothing).
So again the question is whether the syntax g(f2) is authorized by the standard ??
+ If yes (and 14.8.2.2 and 13.4 seems to imply that the answer might be yes), then
some template deduction should happen and the patch must be fixed. But then, if you
consider f2 as a function-type and apply the corresponding lookup rule
then in the previous example g(f2) and g(f2<int>) would have
different behaviours (the first being authorized and not the
second even if the instantiation deduces T=int !!).
What is misleading is that template argument deduction is
certainly authorized for function call...
+ If no I agree that the error message is rather misleading
which is why I proposed in my message to add a better one that states that there is
a syntax error in this case. But again, I might be wrong so I'd
prefer having an advice from someone more acquainted with the arcanes
of the C++ standard before going this way.
Theo.
--------------------------------------------------------------------
Theodore Papadopoulo
Email: Theodore.Papadopoulo@sophia.inria.fr Tel: (33) 04 92 38 76 01
--------------------------------------------------------------------