Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does <algorithm> define a macro X?

I tried to compile the code with option C++14:

#define X static_cast<double>(2)
#include <algorithm>
// if you change the two lines, no error occurs

int main()
{
    return 0;
}

But I get error after X:

error: expected ',' or '...'

I do not get error with option C++98. With my gcc version 4.8.4, I don't get error, but with 5.4.0 I do. Is this a bug? Do I do something wrong?

like image 272
DanielTuzes Avatar asked May 27 '17 13:05

DanielTuzes


1 Answers

I get the same error on my local g++ 5.4.0 installation. I looked at the g++ -E output, and it seems the error traces to /usr/lib/gcc/x86_64-linux-gnu/5/include/ia32intrin.h lines 252 and 254:

/* Write flags register */
extern __inline void
__attribute__((__gnu_inline__, __always_inline__, __artificial__))
__writeeflags (unsigned long long X) // 252
{
  __builtin_ia32_writeeflags_u64 (X); // 254
}

This can be considered a bug in the compiler-bundled library, since non-reserved #defines are not supposed to conflict with them. (Other functions in the same header use parameter __X.)

like image 66
aschepler Avatar answered Oct 18 '22 03:10

aschepler