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

--- Comment #1 from Amir Kirsh <kirshamir at gmail dot com> ---
A more simple example, same internal compiler error:

class Base {
public:
    constexpr bool operator==(const Base& b) const {
        return getIdentity() == b.getIdentity();
    }
private:
    constexpr virtual int getIdentity() const = 0;
};

template<typename ActualType, typename Base1, typename Base2>
class Comparable: public Base1, public Base2 {
public:
    constexpr bool operator==(const Comparable&) const = default;
private:
    constexpr int getIdentity() const override {
        return 1;
    }
};

class A: public Base {};

class B: public Base {};

class AB: public Comparable<AB, A, B> {};

int main() {
    constexpr AB ab_1;
    constexpr AB ab_2;

    // internal compiler error :-(
    static_assert(ab_1 == ab_2);
}

----
Error:

<source>: In instantiation of 'constexpr int Comparable<ActualType, Base1,
Base2>::getIdentity() const [with ActualType = AB; Base1 = A; Base2 = B]':
<source>:4:27:   required from here
    4 |         return getIdentity() == b.getIdentity();
      |                ~~~~~~~~~~~^~
<source>:31:24:   in 'constexpr' expansion of 'ab_1.AB::Comparable<AB, A,
B>.Comparable<AB, A, B>::operator==(ab_2.AB::Comparable<AB, A, B>)'
<source>:13:20:   in 'constexpr' expansion of '((const Comparable<AB, A,
B>*)this)->Comparable<AB, A,
B>::A.A::Base.Base::operator==(<anonymous>.Comparable<AB, A, B>::A.A::Base)'
<source>:17:5: internal compiler error: in use_thunk, at cp/method.cc:324
   17 |     }
      |     ^
0x287e175 diagnostic_context::diagnostic_impl(rich_location*,
diagnostic_metadata const*, diagnostic_option_id, char const*, __va_list_tag
(*) [1], diagnostic_t)
        ???:0
0x28945d5 internal_error(char const*, ...)
        ???:0
0xa90ace fancy_abort(char const*, int, char const*)
        ???:0
0xd1eb6b emit_associated_thunks(tree_node*)
        ???:0
0xd1ed0e expand_or_defer_fn(tree_node*)
        ???:0
0xcc60cd instantiate_decl(tree_node*, bool, bool)
        ???:0
0xb08a50 maybe_constant_value(tree_node*, tree_node*, mce_value)
        ???:0
0xd23df0 finish_static_assert(tree_node*, tree_node*, unsigned int, bool, bool)
        ???:0
0xc9e57a c_parse_file()
        ???:0
0xdf7f99 c_common_parse_file()
        ???:0

----

Code:
https://godbolt.org/z/4x9bMYPhj

Compiles with clang

----

And still, it compiles without the template:
https://godbolt.org/z/Wecqz9YW1

Reply via email to