This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/20812] New: contextual overload resolution failure for a member name found in two base classes


The problem is best demonstrated by a code snippet. The following snippet
shows it as a wrong-code, but if we remove the first function template test
we get a rejects-valid case:

#include <iostream>
#include <ostream>

struct B1 { int foo; };
struct B2 { double foo; };
struct D: B1, B2 { };

template <typename T>
void test(...){
  std::cout << "the class does not have member foo with type 'int B1::*'" << 
std::endl;
}

template <typename T,T t>
struct void_holder { typedef void type; };

template <typename T>
typename void_holder<int B1::*,&T::foo>::type test(T*){
  std::cout << "the class has member foo with type 'int B1::*'" << std::endl;
}

int main(){
  test<D>(0);
}

A specialization of the second function template test should be chosen because
the ambiguity between &B1::foo and &B2::foo can be resolved based on the
context, but a specialization of the first function template test is mistakenly
chosen. (Should we call it "overload" even though I chose non-function members?
Doesn't matter, it's the same with function members anyway.)

There is also a closely connected accepts-invalid case where the ambiguity
causes deduction failure instead of an error, but it's on the edge of core
issue #339. In PR6424 it was decided to say "sorry, unimplemented: call_expr
cannot be mangled due to a defect in the C++ ABI" for most of the cases
covered by core issue #339, but not for all. And this is a failure in one of
those that work:

struct B1 { int foo; };
struct B2 { double foo; };
struct D: B1, B2 { };

template <typename T>
void test(...){ }

template <int>
struct void_holder { typedef void type; };

template <typename T>
typename void_holder<sizeof(&T::foo)>::type test(T*);

int main(){
  test<D>(0); // should cause an error, not a deduction failure
              // for the second function template test
}

Regards,
Vladimir Marko

-- 
           Summary: contextual overload resolution failure for a member name
                    found in two base classes
           Product: gcc
           Version: 3.4.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: SWElef at post dot sk
                CC: gcc-bugs at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20812


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]