While working on the inheriting constructors overhaul I noticed that we were handling this wrong: we were allowing one using-declaration to hide another, but they should both be added so that the ambiguity is seen by overload resolution.
Tested x86_64-pc-linux-gnu, applying to trunk.
commit cda993583ed7eb9270b8758c201894122997c516 Author: Jason Merrill <ja...@redhat.com> Date: Wed Oct 26 13:15:43 2016 -0400 * class.c (add_method): Allow using-declarations to coexist. diff --git a/gcc/cp/class.c b/gcc/cp/class.c index d334b7c..a2a9346 100644 --- a/gcc/cp/class.c +++ b/gcc/cp/class.c @@ -1094,6 +1094,11 @@ add_method (tree type, tree method, tree using_decl) if (TREE_CODE (fn) != TREE_CODE (method)) continue; + /* Two using-declarations can coexist, we'll complain about ambiguity in + overload resolution. */ + if (using_decl && TREE_CODE (fns) == OVERLOAD && OVL_USED (fns)) + continue; + /* [over.load] Member function declarations with the same name and the same parameter types cannot be overloaded if any of them is a static member diff --git a/gcc/testsuite/g++.dg/overload/using4.C b/gcc/testsuite/g++.dg/overload/using4.C new file mode 100644 index 0000000..e4ee823 --- /dev/null +++ b/gcc/testsuite/g++.dg/overload/using4.C @@ -0,0 +1,19 @@ +struct A +{ + void f(); +}; + +struct B +{ + void f(); +}; + +struct C: A,B { + using A::f; + using B::f; +}; + +int main() +{ + C().f(); // { dg-error "ambiguous" } +}