Combining the 'using' directive with partial overload: gcc function or Intel error?

I want to use a set of libraries written in C ++ with Intel compilers. I gave an example of code that demonstrates the problem. There are many places in libraries where they use a combination of "use" with partial overload (for example, I want to use the foo (void) method from the base class, but override the second version of fo foo in the derived class) gcc has no problem, but Intel does .

#include <iostream> template <class F> struct Interface { static const F f=10; }; template <class F> struct Base : public Interface<F> { void foo (void) { std::cout << "void" << std::endl; } template <class FF> void foo (Interface<FF> &ii) { std::cout << "F : " << ii.f << std::endl; } }; template <class F,int i> struct Derived : public Base<F> { // void foo (void) { Base<F>::foo(); } // works fine using Base<F>::foo; // gives error template <class FF> void foo (Interface<FF> &ii) { std::cout << "Derived<" << i << "> F : " << ii.f << std::endl; } }; int main (void) { Derived<double,10> o; o.foo(); // ok o.foo (o); // problem } 

Compiler error given by icc:

 test.cc(30): error: more than one instance of overloaded function "Derived<F, i>::foo [with F=double, i=10]" matches the argument list: function template "void Base<F>::foo(Interface<FF> &) [with F=double]" function template "void Derived<F, i>::foo(Interface<FF> &) [with F=double, i=10]" argument types are: (Derived<double, 10>) object type is: Derived<double, 10> o.foo (o); // problem ^ compilation aborted for test.cc (code 2) 

If you delete the line

 using Base<F>::foo; 

and replace it with a string

 void foo (void) { Base<F>::foo(); } 

everything is working fine.

My question is: does anyone know if this is a special gcc function or icc error? Or is there another work around which will not be related to code changes?

This is with g ++. real (Ubuntu 4.4.3-4ubuntu5) 4.4.3 and icc (ICC) 12.0.2 20110112.

+7
source share
1 answer

For C ++ 11, the corresponding standard quote can be found in

7.3.3 Declaration using [namespace.udecl]

14 / If the function declaration in the namespace or block region has the same name and the same parameter types as the function entered using the declaration-declaration, and the declarations do not declare the same function, the program is poorly formed.

It supports EDG based compilers. However, the special case is intended for use in classes:

15 / When the usage declaration brings names from the base class to the scope of the derived class, the member functions and member function templates in the derived class override and / or hide the member functions and member function templates with the same name, type-type-list ( 8.3.5), cv-qualification and ref-qualifier (if any) in the base class (and not in conflict). [Note. For use-declarations that call a constructor, see 12.9. -end note] [Example:

 struct B { virtual void f(int); virtual void f(char); void g(int); void h(int); }; struct D : B { using B::f; void f(int); // OK: D::f(int) overrides B::f(int); using B::g; void g(char); // OK using B::h; void h(int); // OK: D::h(int) hides B::h(int) }; void k(D* p) { p->f(1); // calls D::f(int) p->f('a'); // calls B::f(char) p->g(1); // calls B::g(int) p->g('a'); // calls D::g(char) } 

-end example]

Therefore, in C ++ 11, it seems that Como and Intel are wrong. I don't know if these rules applied equally in C ++ 03

+5
source

All Articles