Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22199

GCC wrong `missing initializer for member ` warning?

$
0
0

I'm trying to run the following code in my project:

#include <memory>enum class Type{    SpecificType};struct BaseData{    using Ptr = std::unique_ptr<BaseData>;    BaseData(Type type) noexcept : type(type) {}    const Type type;};template <typename T, Type VType>struct Data : BaseData{    using Ptr = std::unique_ptr<T>;    Data() noexcept : BaseData(VType) {}    static Ptr make(T&& val) { return std::make_unique<T>(std::move(val)); }};struct SpecificData : Data<SpecificData, Type::SpecificType>{    int field1;    int field2;};int main(){    SpecificData::Ptr data = SpecificData::make({ .field1 = 13, .field2 = 42 });    return 0;}

My issue is the warning which I get from gcc (trunk)

<source>:35:48: error: missing initializer for member 'SpecificData::<anonymous>' [-Werror=missing-field-initializers]   35 |     SpecificData::Ptr data = SpecificData::make({ .field1 = 13, .field2 = 42 });

The compiler options used for compilation are:

-std=c++20 -Wall -Wextra -Wpedantic -Werror -O2 

I know how to deactivate the warning, or in this case the error beacause of the -Werror, but I want to understand it first, why is it present in the first place.

I don't understand which field remains uninitialized in my SpecificData object.

Could it be the const Type type from the base class which causes the problem?If not, is this a compiler bug?

Note : clang compiles the code without issue with the same flags, so does MSVC with similar flags.


Viewing all articles
Browse latest Browse all 22199

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>