boostorg/mp11

Compile error with MSVC when including `<complex.h>` first

Closed this issue · 6 comments

Got a similar error from Boost.Math reported by Scipy:

In file included from ..\scipy\_lib\boost_math\include\boost/math/policies/policy.hpp:11:
..\scipy\_lib\boost_math\include\boost/math/tools/mp.hpp(171,34): error: expected parameter declarator
  171 | template<typename L, std::size_t I>
      |                                  ^
C:\Program Files (x86)\Windows Kits\10\include\10.0.22621.0\ucrt\complex.h(63,20): note: expanded from macro 'I'
   63 | #define I          _Complex_I

Minimal reproducer: https://godbolt.org/z/KavdnaYMf

The draft C++ ISO states: The header <complex.h> behaves as if it simply includes the header <complex> so I filed an issue against MSVC STL as well.

pdimov commented

Do you want me to do something about this, and if so, what?

When I get the logic in math right I can port it here. Linked PR: boostorg/math#1060

pdimov commented

#pragma push_macro sounds like it might work, yes.

But I notice that the error is coming from your own mp.hpp and not anything here?

It is my own derivative and reduced version of mp11. Your version is susceptible to the same error, and I was going to pull mp11 into odeint to replace MPL.

pdimov commented

Looks like this is only an issue under C++14, but not under C++17 and above (which warns that <ccomplex> is deprecated.)

pdimov commented

Also, looks like it's an issue for GCC (libstdc++) up to 7 as well.