Let's say I have the following C++ code:
#include <cmath>
long double fn_d() {
return pow( double(4), double(3) );
}
long double fn_ld() {
return powl( long double(4), long double(3) );
}
MSVC is happy with this, but both GCC and Clang get confused on the second function, writing (GCC's output):
<source>:6:34: error: expected primary-expression before 'long'
6 | return powl( long double(4), long double(3) );
| ^~~~
Notice that fn_d(...)
above, works just fine. Assuming this isn't a bug in both compilers, what am I supposed to do about it?
Note: (long double)(4)
(i.e., a cast) is not okay. It trips -Wold-style-cast
(which you should be using). Maybe static_cast<long double>(4)
? This feels dirty: I'm constructing an object, not casting an int
, even if the compiler will elide it.