https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90449

            Bug ID: 90449
           Summary: No way to turn off warning about inaccessible base
           Product: gcc
           Version: 9.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: david at doublewise dot net
  Target Milestone: ---

It is possible to pass `-w` to gcc to turn off all warnings, but as far as I
can tell, there is no way to turn off just the warning "direct base ...
inaccessible in ... due to ambiguity". It would be very helpful to me to
disable just this one warning, because I really do not want to turn off the
other on-by-default warnings.

I have a valid use case for needing an ambiguous base class:

https://godbolt.org/z/GG7aR9

In summary, it allows me to implement a tuple that is always empty when given
no non-empty types. The general idea is that `std::get` would delegate to a
member function that accepts an `integral_constant` argument, but each
`tuple_value` class has an overload that accepts only the integral constants
that matches its `index`. This implementation leads to ambiguous base classes
if the user creates a `tuple<T, tuple<T>>`. The base class is inaccessible, but
that doesn't mean that all of its member functions are inaccessible because I
hid the overload that would have conflicted.

The alternative would be to use the more traditional method of implementing
`get` by casting `tuple` to `tuple_value<index, tuple_element_t<index>,
Types...>` and thus having `tuple_value` have all of the types in the tuple as
a trailing variadic parameter to ensure uniqueness in tuples of tuples. This
allows emptiness in all possible cases at the cost of greatly increased symbol
sizes (n^2 template instantiation).

clang also warns on this by default, but has the flag `-Wno-inaccessible-base`
to turn it off.

Reply via email to