google / googletest

GoogleTest - Google Testing and Mocking Framework
https://google.github.io/googletest/
BSD 3-Clause "New" or "Revised" License
34.94k stars 10.16k forks source link

[Bug]: FieldsAre cannot support struct type #4660

Open Kevin-WongCHN opened 2 weeks ago

Kevin-WongCHN commented 2 weeks ago

Describe the issue

the documentation about FieldsAre wrote:

struct MyStruct {
  int value = 42;
  std::string greeting = "aloha";
};
MyStruct s;
EXPECT_THAT(s, FieldsAre(42, "aloha"));

however, when I run this:

struct MyStruct {
  int value = 42;
  std::string greeting = "aloha";
};
TEST(MyTestSuite, FieldsAreMatcherTest) {
    MyStruct s;
    EXPECT_THAT(s, FieldsAre(42, "aloha"));
}

g++ cannot compile: note: types 'std::pair<_Tp1, _Tp2>' and 'const MyStruct' have incompatible cv-qualifiers

Steps to reproduce the problem

wrote the above code and run googletest

What version of GoogleTest are you using?

1.15.2

What operating system and version are you using?

windows10

What compiler and version are you using?

gcc (tdm64-1) 9.2.0

What build system are you using?

cmake version 3.22.2

Additional context

No response

fynnwilliam commented 1 week ago

@Kevin-WongCHN this seams to be a challenge with the compiler version and gets resolved in gcc 11.1 and later. You may also check the reference here.