google / googletest

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

[Bug]: UBSAN finding when using NiceMock #4367

Closed alfalcmar closed 10 months ago

alfalcmar commented 10 months ago

Describe the issue

Running code with UB sanitizer, I get reference binding to null pointer when I use NiceMock with a class that contains a reference member.

Steps to reproduce the problem

https://godbolt.org/z/87ccE1PT3

What version of GoogleTest are you using?

HEAD

What operating system and version are you using?

Not sure what godbolt uses under the hood but I can reproduce it also in ubuntu

What compiler and version are you using?

gcc 9.3

What build system are you using?

-std=c++14 -fsanitize=undefined -fno-sanitize-recover=undefined -O3

Additional context

No response

derekmauro commented 10 months ago

I get the same error in GCC 8.4, 9.3, and 10.2. I get no error in GCC 8.5, 9.4, and 10.3. On that basis, I'm going to say this is likely a UBSAN bug that was fixed in several GCC patch releases.