Fwd: [clang] clang-cl expansion of macros
On 16 April 2016 at 17:58, Edward Diener
What I strongly suspect will finally happen is that clang will not fix these emulation problems because they are too tricky and numerous to do. Instead they will probably declare that their emulation is good enough for the majority of preprocessor constructs and that Boost PP, which pushes the preprocessor to its limits, is not meant to work with their flawed VC++ emulation. I hope I am wrong about that supposition, but having spent much time in Boost PP and Boost VMD trying to workaround VC++ non-standard preprocessor behavior I can envision that having to code "down" to that behavior in numerous complicated instances will be too much time consuming work for the clang developers who have chosen to work with VC++ preprocessor emulation.
I've successfully built boost-1.64 with VC1410 (from the developer command prompt). Trying to use boost with a project using Clang 4.0.0 (both the LLVM and C2 backends) gives me the following PP error messages: 1>------ Rebuild All started: Project: test, Configuration: Debug x64 ------ 1> In file included from test.cpp:16: 1> In file included from z:\vc\x64\include\boost/filesystem.hpp:16: 1> In file included from z:\vc\x64\include\boost/filesystem/path.hpp:28: 1> In file included from z:\vc\x64\include\boost/iterat or/iterator_facade.hpp:12: 1> In file included from z:\vc\x64\include\boost/iterat or/interoperable.hpp:11: 1> In file included from z:\vc\x64\include\boost/mpl/or.hpp:43: 1> In file included from z:\vc\x64\include\boost/mpl/au x_/include_preprocessed.hpp:37: 1>z:\vc\x64\include\boost/mpl/aux_/preprocessed/plain/or.hpp(59,7): error : too many arguments provided to function-like macro invocation 1> 2 1> ^ 1> z:\vc\x64\include\boost/preprocessor/facilities/expand.hpp(26,10): note: macro 'BOOST_PP_EXPAND_I' defined here 1> # define BOOST_PP_EXPAND_I(x) x 1> ^ 1> In file included from test.cpp:16: 1> In file included from z:\vc\x64\include\boost/filesystem.hpp:16: 1> In file included from z:\vc\x64\include\boost/filesystem/path.hpp:28: 1> In file included from z:\vc\x64\include\boost/iterat or/iterator_facade.hpp:12: 1> In file included from z:\vc\x64\include\boost/iterat or/interoperable.hpp:11: 1> In file included from z:\vc\x64\include\boost/mpl/or.hpp:43: 1> In file included from z:\vc\x64\include\boost/mpl/au x_/include_preprocessed.hpp:37: 1>z:\vc\x64\include\boost/mpl/aux_/preprocessed/plain/or.hpp(58,1): error : expected a qualified name after 'typename' 1> BOOST_MPL_AUX_NA_SPEC2( 1> ^ 1> z:\vc\x64\include\boost/mpl/aux_/na_spec.hpp(166,44): note: expanded from macro 'BOOST_MPL_AUX_NA_SPEC2' 1> #define BOOST_MPL_AUX_NA_SPEC2(i, j, name) \ 1> ^ 1> z:\vc\x64\include\boost/mpl/aux_/na_spec.hpp(64,11): note: expanded from macro '\ 1> 1> BOOST_MPL_AUX_NA_SPEC_MAIN' 1> BOOST_MPL_PP_PARAMS(i, typename T) \ 1> ^ 1> z:\vc\x64\include\boost/mpl/aux_/preprocessor/params.hpp(58,11): note: expanded from macro 'BOOST_MPL_PP_PARAMS' 1> , BOOST_MPL_PP_AUX_PARAM_FUNC \ 1> ^ 1> In file included from test.cpp:16: 1> In file included from z:\vc\x64\include\boost/filesystem.hpp:16: 1> In file included from z:\vc\x64\include\boost/filesystem/path.hpp:28: 1> In file included from z:\vc\x64\include\boost/iterat or/iterator_facade.hpp:12: 1> In file included from z:\vc\x64\include\boost/iterat or/interoperable.hpp:11: 1> In file included from z:\vc\x64\include\boost/mpl/or.hpp:43: 1> In file included from z:\vc\x64\include\boost/mpl/au x_/include_preprocessed.hpp:37: 1>z:\vc\x64\include\boost/mpl/aux_/preprocessed/plain/or.hpp(58,1): error : expected ',' or '>' in template-parameter-list Up till now I was using a hacked boost-1.62. So in order to see what would happen, I also built boost-1.63. Apart from a small change in type_with_alignment.hpp (adding a ckeck for _MSC_VER not to exist if __clang__ does exist in line 87), boost-1.63 compiles without a problem (no specific (relevant to the emulation) command line parameters). Is there a macro I should define or is there something else I should set/do in order to use boost-1.64 with Clang 4.0.0 on windows? Any other suggestions? degski -- "*Ihre sogenannte Religion wirkt bloß wie ein Opiat reizend, betäubend, Schmerzen aus Schwäche stillend.*" - Novalis 1798
On 4/29/2017 3:58 AM, degski via Boost wrote:
On 16 April 2016 at 17:58, Edward Diener
wrote: What I strongly suspect will finally happen is that clang will not fix these emulation problems because they are too tricky and numerous to do. Instead they will probably declare that their emulation is good enough for the majority of preprocessor constructs and that Boost PP, which pushes the preprocessor to its limits, is not meant to work with their flawed VC++ emulation. I hope I am wrong about that supposition, but having spent much time in Boost PP and Boost VMD trying to workaround VC++ non-standard preprocessor behavior I can envision that having to code "down" to that behavior in numerous complicated instances will be too much time consuming work for the clang developers who have chosen to work with VC++ preprocessor emulation.
I've successfully built boost-1.64 with VC1410 (from the developer command prompt). Trying to use boost with a project using Clang 4.0.0 (both the LLVM and C2 backends) gives me the following PP error messages:
What are you trying to compile/build/run ? As explained Boost PP does not support clang-cl, which has a buggy emulation of the non-standard VC++ preprocessor. In Boost, using: using clang : 4.0 : some_path/clang++ : <cxxflags>-fmacro-backtrace-limit=0 <cxxflags>-Wno-invalid-token-paste <compileflags>-fmsc-version=1900 <linkflags>-fuse-ld=lld ; you should be able to compile/build Boost libraries. A change was made to Boost PP to support this by having Boost PP use a C++ standard preprocessor whenever both _MSC_VER and __clang__ was defined. This decision was based on the fact that VC++'s clang/c2 uses this mode and should work using the normal Boost Build clang.jam instead of clang-win.jam.
1>------ Rebuild All started: Project: test, Configuration: Debug x64 ------ 1> In file included from test.cpp:16: 1> In file included from z:\vc\x64\include\boost/filesystem.hpp:16: 1> In file included from z:\vc\x64\include\boost/filesystem/path.hpp:28: 1> In file included from z:\vc\x64\include\boost/iterat or/iterator_facade.hpp:12: 1> In file included from z:\vc\x64\include\boost/iterat or/interoperable.hpp:11: 1> In file included from z:\vc\x64\include\boost/mpl/or.hpp:43: 1> In file included from z:\vc\x64\include\boost/mpl/au x_/include_preprocessed.hpp:37: 1>z:\vc\x64\include\boost/mpl/aux_/preprocessed/plain/or.hpp(59,7): error : too many arguments provided to function-like macro invocation 1> 2 1> ^ 1> z:\vc\x64\include\boost/preprocessor/facilities/expand.hpp(26,10): note: macro 'BOOST_PP_EXPAND_I' defined here 1> # define BOOST_PP_EXPAND_I(x) x 1> ^ 1> In file included from test.cpp:16: 1> In file included from z:\vc\x64\include\boost/filesystem.hpp:16: 1> In file included from z:\vc\x64\include\boost/filesystem/path.hpp:28: 1> In file included from z:\vc\x64\include\boost/iterat or/iterator_facade.hpp:12: 1> In file included from z:\vc\x64\include\boost/iterat or/interoperable.hpp:11: 1> In file included from z:\vc\x64\include\boost/mpl/or.hpp:43: 1> In file included from z:\vc\x64\include\boost/mpl/au x_/include_preprocessed.hpp:37: 1>z:\vc\x64\include\boost/mpl/aux_/preprocessed/plain/or.hpp(58,1): error : expected a qualified name after 'typename' 1> BOOST_MPL_AUX_NA_SPEC2( 1> ^ 1> z:\vc\x64\include\boost/mpl/aux_/na_spec.hpp(166,44): note: expanded from macro 'BOOST_MPL_AUX_NA_SPEC2' 1> #define BOOST_MPL_AUX_NA_SPEC2(i, j, name) \ 1> ^ 1> z:\vc\x64\include\boost/mpl/aux_/na_spec.hpp(64,11): note: expanded from macro '\ 1> 1> BOOST_MPL_AUX_NA_SPEC_MAIN' 1> BOOST_MPL_PP_PARAMS(i, typename T) \ 1> ^ 1> z:\vc\x64\include\boost/mpl/aux_/preprocessor/params.hpp(58,11): note: expanded from macro 'BOOST_MPL_PP_PARAMS' 1> , BOOST_MPL_PP_AUX_PARAM_FUNC \ 1> ^ 1> In file included from test.cpp:16: 1> In file included from z:\vc\x64\include\boost/filesystem.hpp:16: 1> In file included from z:\vc\x64\include\boost/filesystem/path.hpp:28: 1> In file included from z:\vc\x64\include\boost/iterat or/iterator_facade.hpp:12: 1> In file included from z:\vc\x64\include\boost/iterat or/interoperable.hpp:11: 1> In file included from z:\vc\x64\include\boost/mpl/or.hpp:43: 1> In file included from z:\vc\x64\include\boost/mpl/au x_/include_preprocessed.hpp:37: 1>z:\vc\x64\include\boost/mpl/aux_/preprocessed/plain/or.hpp(58,1): error : expected ',' or '>' in template-parameter-list
Up till now I was using a hacked boost-1.62. So in order to see what would happen, I also built boost-1.63. Apart from a small change in type_with_alignment.hpp (adding a ckeck for _MSC_VER not to exist if __clang__ does exist in line 87), boost-1.63 compiles without a problem (no specific (relevant to the emulation) command line parameters).
Is there a macro I should define or is there something else I should set/do in order to use boost-1.64 with Clang 4.0.0 on windows? Any other suggestions?
degski
On 29 April 2017 at 21:51, Edward Diener via Boost
What are you trying to compile/build/run ?
An application that pulls in the boost::file_system headers. I am not trying to build boost with clang. For completeness sake, I have the following PP defines: __clang__ BOOST_SP_USE_STD_ATOMIC BOOST_MSVC=1900 BOOST_HAS_MS_INT64
As explained Boost PP does not support clang-cl, which has a buggy emulation of the non-standard VC++ preprocessor.
You have expressed your point of view before and very clearly. In Boost, using:
using clang : 4.0 : some_path/clang++ : <cxxflags>-fmacro-backtrace-limit=0 <cxxflags>-Wno-invalid-token-paste <compileflags>-fmsc-version=1900 <linkflags>-fuse-ld=lld ;
I will eventually try this, thanks for it.
A change was made to Boost PP to support this by having Boost PP use a C++ standard preprocessor whenever both _MSC_VER and __clang__ was defined.
Although we can now (with the above change) build boost with clang, this also implies that we can now NOT use boost in a project on windows (i.e. with windows headers), as the C++ standard preprocessor (the one that gets used) does not play well with the Dinkumware-STL. If it is not clear what I mean, please say so.
This decision was based on the fact that VC++'s clang/c2 uses this mode and should work using the normal Boost Build clang.jam instead of clang-win.jam.
As I wrote before, the same PP errors are generated with both Clang/LLVM and Clang/C2, there is no difference in behaviour between the two. There is an additional issue that AFAICS (due to the (relatively simplistic) way things are done by the clang team) there is no way to call clang++.exe from the IDE. All compilers supplied by Clang/LLVM are just copies of the same file with different names (same hash values for all (compiler) files). A different name invokes different behaviour. msbuild calls C:\Program Files (x86)\LLVM\msbuild-bin\cl.exe (which is just another copy of the same compiler). f.e. to get the build information, one has to use different commands:
clang++ --version (linux style) clang-cl -v (windows style)
even though the only difference is the name (and therefor the command) of the files. If you (as I suspect you will) say it's a mess, I fully agree. I do think, though, that it's less usefull to be able to build boost with clang (as it also builds with VC), than it is to be able to use boost (compiled, whatever way) in a project from the IDE. boost-1.63 works (adjusted), boost-1.64 doesn't, this cannot be seen as progress IMHO. If I don't make sense or if I'm missing something, please tell me. Have a good day, degski -- "*Ihre sogenannte Religion wirkt bloß wie ein Opiat reizend, betäubend, Schmerzen aus Schwäche stillend.*" - Novalis 1798
For completeness sake, I have the following PP defines:
__clang__ BOOST_SP_USE_STD_ATOMIC BOOST_MSVC=1900 BOOST_HAS_MS_INT64
BOOST_MSVC=1900 looks odd; this macro should only be defined when the
compiler is MSVC.
Either way, I tried
#include
On 30 April 2017 at 14:41, Peter Dimov via Boost
BOOST_MSVC=1900 looks odd; this macro should only be defined when the compiler is MSVC.
No, don't think so. Remember, both __MSC_VER and __clang__ are defined. With or without this macro, the result is the same, I tried that.
Either way, I tried
#include
int main() { }
This works fine for me as well, I get an executable that does nothing. I also tried it (for you), even including all the headers (just to rule out some interaction) in the project concerned (many more), same result, still compiles. Optimisation at work... degski -- "*Ihre sogenannte Religion wirkt bloß wie ein Opiat reizend, betäubend, Schmerzen aus Schwäche stillend.*" - Novalis 1798
On 30 April 2017 at 15:34, degski
This works fine for me as well, I get an executable that does nothing. I also tried it (for you), even including all the headers (just to rule out some interaction) in the project concerned (many more), same result, still compiles. Optimisation at work...
Apologies, no, it doesn't work for me (was erronously including the 1.63 headers). What macros do you have defined? Are you compiling from the IDE? degski -- "*Ihre sogenannte Religion wirkt bloß wie ein Opiat reizend, betäubend, Schmerzen aus Schwäche stillend.*" - Novalis 1798
degski wrote:
Apologies, no, it doesn't work for me (was erronously including the 1.63 headers). What macros do you have defined? Are you compiling from the IDE?
No macros except the default (WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)), yes, from the IDE. I'm not using clang 4 though, but the clang that ships with 2017.
On 30 April 2017 at 16:03, Peter Dimov via Boost
No macros except the default (WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)), yes, from the IDE. I'm not using clang 4 though, but the clang that ships with 2017.
I'm also just using (a.o.) the clang that ships with 2017. I don't get it... Just a (I would think) stupid question: "Are the generated boost headers different, if/when compiled with clang++?" I'm going to do a Schwarzenegger: "I'll be back!" degski -- "*Ihre sogenannte Religion wirkt bloß wie ein Opiat reizend, betäubend, Schmerzen aus Schwäche stillend.*" - Novalis 1798
degski wrote:
I'm also just using (a.o.) the clang that ships with 2017. I don't get it...
I checked the master branch, works. Then checked a downloaded 1_64_0, fails: 1>------ Build started: Project: testbed2017, Configuration: Debug Win32 ------ 1>testbed2017.cpp 1>In file included from testbed2017.cpp:1: 1>In file included from D:/boost_1_64_0\boost/filesystem.hpp:16: 1>In file included from D:/boost_1_64_0\boost/filesystem/path.hpp:28: 1>In file included from D:/boost_1_64_0\boost/iterator/iterator_facade.hpp:12: 1>In file included from D:/boost_1_64_0\boost/iterator/interoperable.hpp:11: 1>In file included from D:/boost_1_64_0\boost/mpl/or.hpp:43: 1>In file included from D:/boost_1_64_0\boost/mpl/aux_/include_preprocessed.hpp:37: 1>D:/boost_1_64_0\boost/mpl/aux_/preprocessed/gcc/or.hpp(63,1): error : pasting formed 'BOOST_PP_TUPLE_ELEM_O_3(', an invalid preprocessing token [-Winvalid-token-paste] 1>BOOST_MPL_AUX_NA_SPEC2( 1>^ This is exactly how clang used to fail before the changes, if I recall. I'm now checking out the boost-1.64.0 tag to see how it would fare.
I'm now checking out the boost-1.64.0 tag to see how it would fare.
boost-1.64.0 fails as well.
Mystery solved, the changes that fixed clang are not in 1.64.
C:\Projects\boost-git\boost\libs\preprocessor>git log boost-1.64.0..master
commit b19e4deacb7103061f9c2c9efcdd77eaa5877df0
Merge: a627594 dfc1c46
Author: Edward Diener
On 4/30/2017 10:06 AM, Peter Dimov via Boost wrote:
I'm now checking out the boost-1.64.0 tag to see how it would fare.
boost-1.64.0 fails as well.
Mystery solved, the changes that fixed clang are not in 1.64.
I did not put those changes in 1.64. I did not think I had enough time between when the changes were tested on the 'develop' branch and when 1.64 was closed for all but the most serious changes. I have, as you discovered, merged those changes to master after 1.64 was out.
C:\Projects\boost-git\boost\libs\preprocessor>git log boost-1.64.0..master commit b19e4deacb7103061f9c2c9efcdd77eaa5877df0 Merge: a627594 dfc1c46 Author: Edward Diener
Date: Mon Apr 24 12:13:09 2017 -0400 Merge branch 'develop'
commit dfc1c46ecedef21274eb142e267e91400aa33ec8 Author: Edward Diener
Date: Sun Mar 26 08:51:41 2017 -0700 With _MSC_VER and __clang__ always use strict mode and variadics turned on w
commit e474eea44f00ba92310ace20add3956adb83f3de Author: Edward Diener
Date: Sun Mar 26 01:02:05 2017 -0700 Slight correction to particularize previous change as involving only -fno-ms
commit b03c6cd3c0f855f22f154424272ef9276ed72594 Author: Edward Diener
Date: Sat Mar 25 23:22:32 2017 -0700 In the configuration the combination of clang defined and gcc defined always
On 30 April 2017 at 17:06, Peter Dimov via Boost
I'm now checking out the boost-1.64.0 tag to see how it would fare.
boost-1.64.0 fails as well.
Mystery solved, the changes that fixed clang are not in 1.64.
I'm happy you found that, Peter. an I'm even more happy I'm not yet going totally bonkers. Would it be possible to release 1.64.1? degski -- "*Ihre sogenannte Religion wirkt bloß wie ein Opiat reizend, betäubend, Schmerzen aus Schwäche stillend.*" - Novalis 1798
On 30 April 2017 at 16:15, degski
I'm going to do a Schwarzenegger: "I'll be back!"
I grabbed the development branch preprocessor source from github. Now it works (this limited use of boost), both with Clang/LLVM and Clang/C2. Many thanks and have a good day, degski -- "*Ihre sogenannte Religion wirkt bloß wie ein Opiat reizend, betäubend, Schmerzen aus Schwäche stillend.*" - Novalis 1798
I've created a new project, copied your code, same result... The program (if you can call it that) actually works (compiles) with VC1410, but not with either of the clang versions. What am I doing wrong (or differently)? degski
participants (3)
-
degski
-
Edward Diener
-
Peter Dimov