ADL beachtet Namespace von template Argument eines übergebenen Klassenobjetes?



  • Hallo

    namespace A
    {
    	class Bar
    	{
    	};
    
    	template<class Arg> void test(Arg){}
    }
    
    namespace B
    {
    	template<class Dub>
    	class Foo
    	{
    		typedef Dub d;
    	};
    
    	class Foo2
    	{
    		typedef A::Bar d;
    	};
    
    	template<class Arg> void test(Arg){}
    }
    
    int main()
    {
    	B::Foo<A::Bar> f;
    	test(f);/*
    gcc 4.4:
    main.cpp: In function 'int main()':
    main.cpp:29: error: call of overloaded 'test(B::Foo<A::Bar>&)' is ambiguous
    main.cpp:23: note: candidates are: void B::test(Arg) [with Arg = B::Foo<A::Bar>]
    main.cpp:7: note:                 void A::test(Arg) [with Arg = B::Foo<A::Bar>]
    */
    
    	B::Foo2 f2;
    	test(f2);//OK
    }
    

    Wieso beachtet der Compiler hier den A-Namespace? Ist dies Standardkonform? Falls ja, wo ist dies definiert? Ich konnte im aktuellen working draft leider nichts finden 😞

    Danke!



  • Ja, es steht so im Standard:

    ISO-C++ §3.4.2/2 schrieb:

    For each argument type T in the function call, there is a set of zero or more associated namespaces and a set of zero or more associated classes to be considered.
    [...]
    If T is a non-archetype class type (including unions), its associated classes are: the class itself; the class
    of which it is a member, if any; and its direct and indirect base classes. Its associated namespaces are the namespaces of which its associated classes are members. Furthermore, if T is a class template specialization, its associated namespaces and classes also include: the namespaces and classes associated with the types of the template arguments provided for template type parameters (excluding template template parameters); the namespaces of which any template template arguments are members; and the classes of which any member templates used as template template arguments are members. [ Note: non-type template arguments do not contribute to the set of associated namespaces.—end note ]



  • Danke


Anmelden zum Antworten