5

Consider the following, minimal example:

struct T { void operator()() { } };
struct S { void operator()(int) { } };

struct U: T, S {
    U(): T{}, S{} { }
    //using T::operator();
    //using S::operator();
};

int main() {
    U u;
    u(42);
}

It compiles as it is with clang 3.8.
Anyway, it fails to compile with GCC 6.1 with the error:

12 : error: request for member 'operator()' is ambiguous

Note that GCC 6.1 works fine if the using directives are uncommented.
As far as I know, there is no reason for such an error and it seems that clang is the one that works as expected.

Before to open a bug to I don't know who, I'd like to ask if there is something that I missed.
In other terms, to give an error is the right behavior in this case or it's an error for itself?

skypjack
  • 49,335
  • 19
  • 95
  • 187
  • 2
    Really. There is no overloading across scopes in C++. – T.C. Jun 25 '16 at 14:13
  • I think gcc is right. Overload selection is usually done after it figures out the scope. In this case, it can't select the base class I question due to the ambiguity – Dave S Jun 25 '16 at 14:16
  • @T.C. Right, wrong tag. Anyway, the call to `operator()` is not ambiguous because of the parameters. Am I wrong? – skypjack Jun 25 '16 at 14:16
  • I thought that the scope in this case was `U` due to the `using` declarations. – Dietrich Epp Jun 25 '16 at 14:17
  • If the using statements are there, it works, and the scope is the struct U. Without the using clauses, it should fail due to ambiguity – Dave S Jun 25 '16 at 14:19
  • @DaveS Uhm, I got it, it makes sense, haven't thought about that... Would you add an answer with the details? – skypjack Jun 25 '16 at 14:20

0 Answers0