Skip to content

"May be used uninitialized" warning from g++ 15.2.1 with -O2 #629

@Kirisummer

Description

@Kirisummer

First of all, thanks for the library, it is very useful!

I included the library sources (reflectcpp.cpp, reflectcpp_json.cpp and yyjson.c) to my sources and tried building them unoptimized and optimized. Build succeeds without -O flag and with -O1, but some warnings appear with -O2.

Example code (main.cpp):

#include <cstdint>
#include <variant>
#include <vector>
#include <iostream>

#include "rfl/json.hpp"
#include "rfl.hpp"

enum class Enum1 {
    Val1, Val2
};

enum class Enum2 {
    Val1, Val2
};

enum class Enum3 {
    Val1, Val2
};

struct Struct1 {
    Enum1 e1;
    Enum2 e2;
};

struct Struct2 {
    Enum3 e3;
};

using Variant = std::variant<Struct1, Struct2>;
using Vector = std::vector<Variant>;

int main() {
    Struct1 s1{Enum1::Val1, Enum2::Val2};
    Struct2 s2{Enum3::Val1};
    Vector vec{s1, s2};

    std::stringstream stream;
    rfl::json::write<rfl::AddTagsToVariants>(vec, stream);
    const auto res = rfl::json::read<Vector, rfl::AddTagsToVariants>(stream);
    if (res) {
        rfl::json::write<rfl::AddTagsToVariants>(res.value(), std::cout) << '\n';
    } else {
        std::cerr << "Failed to read Vector: " << res.error().what() << '\n';
    }
}

Compiler command:
g++ -Wall -std=c++23 -Werror main.cpp src/reflectcpp.cpp src/reflectcpp_json.cpp src/yyjson.c -I lib/reflect-cpp/include/ -I lib/reflect-cpp/include/rfl/thirdparty/ -O2 >& error.txt

Compiler output is very big, so I'm attaching a separate file: error.txt

reflect-cpp is checked out on tag v0.24.0, g++ version is 15.2.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions