Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GCC 5+ generates invalid code due to UB #76

Open
mikedld opened this issue Mar 31, 2017 · 0 comments
Open

GCC 5+ generates invalid code due to UB #76

mikedld opened this issue Mar 31, 2017 · 0 comments

Comments

@mikedld
Copy link

mikedld commented Mar 31, 2017

GCC 4 (tested with 4.4.7, 4.8.5, 4.9.4) generates working code even with optimizations enabled. GCC 5+ (tested with 5.4.0, 6.3.0) OTOH generates invalid (aborting, segfaulting, infinitely looping) code even with -O1. I guess it's worth mentioning on the wiki page that optimizations bring trouble not only in the case of MSVC.

Out of curiosity,

  1. Is it possible to enable optimizations but still get working code (with some compiler attributes or other magic)? We're currently building both binaries for release (so, with optimizations enabled) and their unit tests in one go.
  2. Is it possible to implement HippoMocks in non-UB way with current C++ standards (up to C++17)?

P.S. Clang (tested with Apple Clang 8.1.0 from Xcode 8.3) currently generates working code regardless of optimization level.

P.P.S. Sample code used in tests:

#include "hippomocks.h"

struct A { virtual ~A() {} };

int main()
{
    HippoMocks::MockRepository mocks;

    A* a = mocks.Mock<A>();
    mocks.ExpectCallDestructor(a);
    delete a;

    return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant