The macro M_PI, which expands to a constant approximating the value
of pi, is defined by POSIX, but not by ISO C or ISO C++. It is
not a reserved identifier, so it should be available for use as a
The problem: Including <cmath> causes M_PI to be defined, even when
the C++ compiler is invoked in what should be a conforming mode.
This problem occurs with clang++. It does not occur with g++.
EXPECTED: Program compiles without error and prints "3".
OBSERVED: Program is rejected at compile time.
(The program is rejected when g++ or clang++ is invoked without
options. That's not a bug.)
Using <math.h> rather than <cmath> doesn't change the symptom.
A similar program in C does not exhibit the problem.
I *think* the problem is in the "math.h" header, which should arrange
for M_PI and similar macros not to be defined in conforming mode.
It's also possible that a fix might involve updates to clang++.
I haven't fully investigated the twisty maze of macro definitions
and nested #includes in math.h.
(I acknowledge that writing your own definition of M_PI is not a
good idea, and that the definition in this program is particularly
I'm using 64-bit Cygwin on Windows 10, with all the latest updates.