xtypes icon indicating copy to clipboard operation
xtypes copied to clipboard

SIGABRT when directly accessing value of float from member

Open russkel opened this issue 2 years ago • 2 comments

I am compiling using C++20 on GCC 11:

Simple Structure definition:

    StructType msg("Msg");
    msg.add_member("latitude", primitive_type<float>());
    msg.add_member("longitude", primitive_type<float>());

This is inside a Catch2 test case:

// Works
  REQUIRE(msg["latitude"].value<float>() == Approx(-11.11293));

// SIGABRT
  REQUIRE(msg["latitude"] == Approx(-11.11293));

I believe this should error at compile time if it doesn't know what the return type is going to be.

russkel avatar Jul 29 '22 00:07 russkel

It must be an issue specific to Catch2 because I'm not able to reproduce this on GoogleTest:

    TEST (StructType, issue110)
    {
        StructType s("Msg");
        s.add_member("latitude", primitive_type<float>());
        s.add_member("longitude", primitive_type<float>());

        DynamicData msg(s);
        msg["latitude"] = -11.11293f;
        EXPECT_FLOAT_EQ(msg["latitude"].value<float>(), -11.11293);
        EXPECT_FLOAT_EQ(msg["latitude"], -11.11293);
    }

works flawlessly on all supported platforms.

MiguelBarro avatar Jan 26 '23 10:01 MiguelBarro

Bizarre. I'll try this again and then maybe report to catch2 instead.

russkel avatar Jan 26 '23 10:01 russkel