eranpeer / FakeIt

C++ mocking made easy. A simple yet very expressive, headers only library for c++ mocking.
MIT License
1.24k stars 173 forks source link

Pragma GCC diagnostic push missing #160

Closed Stannieman closed 5 years ago

Stannieman commented 5 years ago

The code

#ifdef __GNUG__
#ifndef __clang__
#pragma GCC diagnostic ignored "-Wpedantic"
#endif
#endif

Should be changed to

#ifdef __GNUG__
#ifndef __clang__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wpedantic"
#endif
#endif

The reason is that otherwise the diagnostic pop that comes later will also remove any diagnostic pragma that was added by the consumer of this library.

In our solution for example we do something like

#ifdef __GNU__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wsomeotherwarning1"
#pragma GCC diagnostic ignored "-Wsomeotherwarning2"
#pragma GCC diagnostic ignored "-Wsomeotherwarning2"
#include "fakeit.hpp"
#ifdef __GNU__
#pragma GCC diagnostic pop
#endif

for ALL third party headers to ensure our compilation log is not spammed with warnings from not-our-code. Because FakeIt currently does not do diagnostic push before ignoring the warning the pop that comes later will remove ALL other diagnostic ignored pragmas we defined. If a push is added first then the pop will only remove up to that push, leaving our own pragmas intact.

PR: https://github.com/eranpeer/FakeIt/pull/161

alibabashack commented 5 years ago

@Stannieman The related pull request #161 was merged. Can this issue be closed?

Stannieman commented 5 years ago

Of course!