2

I am trying to implement a basic mixin using CRTP.

When I try to create an object of my class I get the following warning:

error: missing initializer for member 'my_mixin::<anonymous>' [-Werror=missing-field-initializers]

My code is as follow


template<typename U, template<typename...> class... CRTP>
struct ops: CRTP<U>... {};

template<typename T>
struct listed { using list = std::vector<T>; };

template<typename T>
struct eq { bool operator==(const eq<T>& other) const = default; };

struct my_mixin: ops<my_mixin,listed,eq> {
    uint32_t uuid;
    std::string name;
};

int main(int, char**) {
    const my_mixin carrier = {
        .uuid = 1234,
        .name = std::string{"name"},
    };
}

Example on compiler explorer: https://godbolt.org/z/eY4McoK69

What am I missing?

Is it possible to get past the issue without disabling the warning in the compiler?

Additional: This compiles without issue on Clang 16 and MSVC 19. As @barry pointed out it appears to be a gcc bug.

CJCombrink
  • 3,738
  • 1
  • 22
  • 38
  • Does this answer your question? [Designated initializers in C++20](https://stackoverflow.com/questions/58876020/designated-initializers-in-c20) – Nelfeal May 31 '23 at 15:40
  • 3
    Seems like a gcc bug, submitted [#110064](https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110064). – Barry May 31 '23 at 15:43
  • @Nelfeal No unfortunately it does not answer the question. The question linked have a similar issue, and there the bases does have their own members. In this case, all non static members of the final class is initialised still the compiler complains (see the bug submitted by @Barry) – CJCombrink Jun 01 '23 at 06:23

0 Answers0