rollbear / trompeloeil

Header only C++14 mocking framework
Boost Software License 1.0
802 stars 85 forks source link

Fix macro variadic arguments expansion on MSVC #301

Closed gregkalata closed 1 year ago

codecov[bot] commented 1 year ago

Codecov Report

Merging #301 (1f41e60) into main (cea5afb) will not change coverage. The diff coverage is n/a.

@@           Coverage Diff           @@
##             main     #301   +/-   ##
=======================================
  Coverage   97.99%   97.99%           
=======================================
  Files           1        1           
  Lines        1345     1345           
=======================================
  Hits         1318     1318           
  Misses         27       27           
Impacted Files Coverage Δ
include/trompeloeil.hpp 97.99% <ø> (ø)
rollbear commented 1 year ago

OK. Good, I think. Can you explain what problem this solves? Can you add a test that fails on MSVC without it?

gregkalata commented 1 year ago

I have added a test case that should not compile on MSVC. The problem boils down to the way MSVC expands __VA_ARGS__. I've encountered it when using .IN_SEQUENCE macro. With one or two sequences it works fine, but with third one it causes a compile error. For example: .IN_SEQUENCE(seq3, seq2, seq1); will cause the following error: trompeloeil\test\compiling_tests_11.cpp(304,1): error C2440: '<function-style-cast>': cannot convert from 'initializer list' to 'trompeloeil::sequence_matcher::init_type' trompeloeil\test\compiling_tests_11.cpp(304,1): message : No constructor could take the source type, or constructor overload resolution was ambiguous

The issue with macro expansion was discussed on SO and a workaround was suggested there. The issue goes away as well if you specify /Zc:preprocessor argument, but in my codebase it caused loads of issues in many places, so I decided to use the workaround instead.

rollbear commented 1 year ago

Thank you! Much appreciated.