Skip to content

[Bug]: IsEmpty matcher doesn't work with C-style wide strings #4857

@mondious

Description

@mondious

Describe the issue

Compiling a test with the following excerpt fails.
ASSERT_THAT(L"NotEmpty", Not(IsEmpty()));

In file included from /opt/compiler-explorer/libs/googletest/trunk/googlemock/include/gmock/gmock.h:61,
                 from <source>:1:
/opt/compiler-explorer/libs/googletest/trunk/googlemock/include/gmock/gmock-more-matchers.h: In instantiation of 'bool testing::internal::IsEmptyMatcher::MatchAndExplain(const MatcheeContainerType&, testing::MatchResultListener*) const [with MatcheeContainerType = wchar_t [9]]':
/opt/compiler-explorer/libs/googletest/trunk/googletest/include/gtest/gtest-matchers.h:647:35:   required from 'bool testing::PolymorphicMatcher<Impl>::MonomorphicImpl<T>::MatchAndExplain(T, testing::MatchResultListener*) const [with T = const wchar_t (&)[9]; Impl = testing::internal::IsEmptyMatcher]'
/opt/compiler-explorer/libs/googletest/trunk/googletest/include/gtest/gtest-matchers.h:646:10:   required from here
/opt/compiler-explorer/libs/googletest/trunk/googlemock/include/gmock/gmock-more-matchers.h:70:11: error: request for member 'empty' in 'c', which is of non-class type 'const wchar_t [9]'
   70 |     if (c.empty()) {
      |         ~~^~~~~
/opt/compiler-explorer/libs/googletest/trunk/googlemock/include/gmock/gmock-more-matchers.h:73:40: error: request for member 'size' in 'c', which is of non-class type 'const wchar_t [9]'
   73 |     *listener << "whose size is " << c.size();
      |                                      ~~^~~~
Compiler returned: 1

The overload of IsEmpty for C-style wide strings seems to be missing. The documentation mentions that there should be one.

The testcase does not check for C-style wide string compatibility.

Steps to reproduce the problem

See a minimal example here.

What version of GoogleTest are you using?

Trunk was used in godbolt, so it should be a quite recent version.
I also use v1.17.x on my computer.

What operating system and version are you using?

Windows 11 24H2

What compiler and version are you using?

Reproducible on both gcc-11.4.0 and clang-14.

What build system are you using?

cmake version 4.0.3

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions