trompeloeil
trompeloeil copied to clipboard
Ambiguous type name leads to unusual compiling error
In the following example:
#include "trompeloeil.hpp"
namespace A { class Foo {}; }
namespace B { class Foo {}; }
using namespace A;
using namespace B;
struct Bar {
MAKE_MOCK1(onFoo, void(Foo));
};
The error one gets is:
/home/mgodbolt/dev/algo/mambo/test/trompeloeil.hpp:3319:70: error: template argument 1 is invalid
std::integral_constant<bool, num == ::trompeloeil::param_list<sig>::size>; \
^
/home/mgodbolt/dev/algo/mambo/test/trompeloeil.hpp:3252:3: note: in expansion of macro ‘TROMPELOEIL_MAKE_MOCK_’
TROMPELOEIL_MAKE_MOCK_(name,,1, __VA_ARGS__,,)
^~~~~~~~~~~~~~~~~~~~~~
.... ~500 more lines in a similar fashion
There's no mention of any ambiguity in the error messages. This is somewhat confusing (but quite possibly not fixable). Of course, the code is incorrect and without the MOCK macro if one writes just struct Bar {void onFoo(Foo); } one gets a more sane error from GCC:
void onFoo(Foo);
These errors and this behaviour was seen with GCC 6.3 and trompeloeil v22. Perhaps a FAQ entry if there's no way to surface the real underlying error.
Thanks @mattgodbolt. It can be difficult to trick the compiler into providing good information for ill formed programs, but at times it can be done. I'll see what I can do.
Curiously, clang++-3.9 is very clear on what the problem is:
c.cpp:17:28: error: reference to 'Foo' is ambiguous
MAKE_MOCK1(onFoo, void(Foo));
^
/var/tmp/trompeloeil/trompeloeil.hpp:3576:35: note: expanded from macro 'MAKE_MOCK1'
#define MAKE_MOCK1 TROMPELOEIL_MAKE_MOCK1
^
c.cpp:5:11: note: candidate found by name lookup is 'A::Foo'
class Foo {};
^
c.cpp:9:11: note: candidate found by name lookup is 'B::Foo'
class Foo{};
^
Reported this as a gcc bug: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79070