veselink1/refl-cpp

Visual Studio 2017 code formatter breaks compilation for refl.hpp

ScottHutchinson opened this issue · 10 comments

Create a new C++ console application. Set warnings to level 4. Target latest. Build with the Visual Studio 2017 (v141) compiler:

Severity	Code	Description	Line	File	Project	Suppression State
Error	C2760	syntax error: unexpected token 'identifier', expected 'type specifier'	2563	..\refltestconsole\refl.hpp	ReflTestConsole	
Error	C2270	'MemberName_': modifiers not allowed on nonmember functions	2565	..\refltestconsole\refl.hpp	ReflTestConsole	
Error	C2995	'decltype(auto) MemberName_(Args &&...)': function template has already been defined	2568	..\refltestconsole\refl.hpp	ReflTestConsole	
Error	C2059	syntax error: '}'	2569	..\refltestconsole\refl.hpp	ReflTestConsole	
Error	C2143	syntax error: missing ';' before '}'	2569	..\refltestconsole\refl.hpp	ReflTestConsole	
Error	C2143	syntax error: missing ';' before '{'	2610	..\refltestconsole\refl.hpp	ReflTestConsole	
Error	C2447	'{': missing function header (old-style formal list?)	2610	..\refltestconsole\refl.hpp	ReflTestConsole	
Error	C2143	syntax error: missing ';' before 'namespace'	2771	..\refltestconsole\refl.hpp	ReflTestConsole	
Error	C1075	'{': no matching token found	2779	..\refltestconsole\refl.hpp	ReflTestConsole	

Hi! It compiles without errors on the v142 (VS 2019) toolchain with language standard set to C++17. I will be testing on v141 soon.

I was able to compile and run all the examples successfully with Visual Studio 2019 with the VS 2017 Build Tools (v141) version 15.9.23, at /W4, with both -std=c++17 and -std=c++latest. I wasn't able to run the tests, however, as it seems that lambdas in a constexpr context are not fully supported in v141 (compiles fine with v142), but that is easily fixable.

Could this be a bug with an older version of the v141 toolchain? Would you mind sharing specific build tools version number and maybe some source code?

Also, is this on the lastest v0.9.1 release? I am unable to find some of the symbols mentioned in the error output at the specified line.

I can however see two things which might be the culprit.
Trailing \ at refl.hpp:2798
Comment in macro at refl.hpp:2785

It is happening with the latest version of Visual Studio 2017, which is 15.9.23. I also reproduced it in Visual Studio 2019, but with the 2017 compiler v141.
You can get my source code at https://github.com/ScottHutchinson/ReflTestConsole

The rfl.hpp content is identical to the one in the master branch.
I've never seen code with so many \ for line continuation, so maybe that is causing the problem.

From the build log:

       ClCompile:
         C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.16.27023\bin\HostX86\x86\CL.exe /c /ZI /JMC /nologo /W4 /WX- /diagnostics:classic /sdl /Od /Oy- /D WIN32 /D _DEBUG /D _CONSOLE /D _UNICODE /D UNICODE /Gm- /EHsc /RTC1 /MDd /GS /fp:precise /permissive- /Zc:wchar_t /Zc:forScope /Zc:inline /std:c++latest /Fo"Debug\\" /Fd"Debug\vc141.pdb" /Gd /TP /analyze- /FC /errorReport:prompt ReflTestConsole.cpp

Retargeting to the v142 compiler does not help.

Strange. There seems to be something wierd happending with your refl.hpp file.
v0.9.1 refl.hpp:2791
your refl.hpp:2559
The macro definition seems all broken up in your version. I am unable to reproduce running git clone on Windows or Linux, so it is curious as to what has caused this.

Replacing with the v0.9.1 source fixes the issue. Can you confirm that this fixes it for you as well?

When I compare the file I tested with the one in master, they are binary same.

The only difference I see between the two files you referenced above is that the opening { are on the their own line in the v0.9.1 file. My IDE is set to automatically format C++ files with the opening { on the same line with the function definition, etc. EDIT: Oh, I think the formatter is moving the \ too, which is probably what is breaking it.

Yeah, that fixes it. I just manually moved about four \ to the previous line. Now it builds.

Glad you were able to resolve this! Seems to be related to the multiline comment in the macro at refl.hpp:2553, as the breaking changes made by the formatter are right after that. I will be moving that multiline comment out of the macro with the next release, so that should fix it for anyone using code formatters.