eranpeer / FakeIt

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

Defining DWORD inside fakeit namespace causes issues due to pre-2017 MSVC bug #105

Closed lighterowl closed 6 years ago

lighterowl commented 7 years ago

MSVC versions before 2017 (i.e. 2015 and older) have a bug where defining a typedef inside a namespace causes name lookup issues if a given translation unit uses that namespace inside an anonymous namespace. Try compiling the code below with any pre-2017 version :

namespace foobar { typedef unsigned long myulong; }
typedef unsigned long myulong;
namespace { using namespace foobar; }
void a(int b) { static_cast<myulong>(b); }

The compiler will throw following errors :

err.cpp(4): error C2872: 'myulong': ambiguous symbol
err.cpp(2): note: could be 'unsigned long myulong'
err.cpp(1): note: or       'foobar::myulong'

Analogous errors happen when including fakeit.h and trying to use DWORD in any of the translation unit's global functions later on. Here's a minimal example :

#include "fakeit.hpp"
#include <windows.h>
namespace { using namespace fakeit; }
void globalfn(int x) { static_cast<DWORD>(x); }