google / googletest

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

Crash with std::bad_alloc when building against latest abseil 20200923.1 #3071

Open emmenlau opened 4 years ago

emmenlau commented 4 years ago

I'm trying to build against abseil and found a new release 20200923.1 from two weeks ago. I build using cmake, by adding the definition GTEST_HAS_ABSL and linking against the required absl libraries. The build works fine and I did not see any noteworthy warnings.

However when running google test, I get a std::bad_alloc on every ASSERT. I traced the problem in gtest to https://github.com/google/googletest/blob/master/googletest/src/gtest.cc#L4834, and from there into absl to https://github.com/abseil/abseil-cpp/blob/4b915e70929ca2d6152240facc83d3d38c5d5f28/absl/strings/str_cat.cc#L202

If I replace absl::StrAppend(&result, kElidedFramesMarker, "\n"); with a simple result += std::string(kElidedFramesMarker) + "\n"; everything works as expected.

I'm a bit lost there as to what is going wrong, help would be appreciated.

I tried with gtest 1.10.0 and latest master, both show the same behavior.

My environment is Ubuntu 20.04 with gcc9, x86_64. I've set the c++ standard to c++17 in absl.

derekmauro commented 4 years ago

Can you please provide the full reproduction? We need to know exactly what you did. Maybe simple a GitHub repo that I can pull and run?

emmenlau commented 4 years ago

Thanks @derekmauro for your quick action.

I wanted to provide this anyways as a PR for the community, in the hope that it will be useful. There was a minor typing error before, but now https://github.com/google/googletest/pull/3072 should be ready. Can you please take a look?

emmenlau commented 4 years ago

@derekmauro does the PR work for you to reproduce the issue?