Another case where whitespace matters (maybe?)
Asked Answered
C

1

10

Is this another case, where whitespace matters in C++, or is it a compiler bug? Is the following code syntactically correct?

#include <type_traits>

template <bool cond>
using EnableIf = typename std::enable_if<cond, int>::type;

template <int n, EnableIf<n == 1>=0>
void func()
{}

Intel C++ Composer fails to compile it saying: "invalid combination of type specifiers". But add single whitespace in the signature and it compiles just fine:

template <int n, EnableIf<n == 1> =0>
void func()
{}
Centrifugal answered 19/12, 2012 at 11:29 Comment(1)
Well, it's not supposed to be <n == (1>=0)>Microclimate
O
18

It's a case where whitespace matters. The compiler will match the biggest symbol it can, so it matches >=. The whitespace causes it to parse as you intended.

Ostwald answered 19/12, 2012 at 11:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.