#include <type_traits>
#include <iostream>
void f()
{}
#define M1(...) \
if constexpr (std::is_void_v<decltype(__VA_ARGS__)>)\
{ std::cout << "is_void" << std::endl; }\
else\
{ std::cout << "is_not_void" << std::endl; }
#define M2(...) \
if constexpr (std::is_void_v<decltype(__VA_ARGS__)>)\
{ __VA_ARGS__; }\
else\
{ auto tmp = __VA_ARGS__; }
int main()
{
M1(f()); // OK! output "is_void"
M2(f());
// compiler error:
// variable has incomplete type 'void' at line: auto tmp = __VA_ARGS__;
}
My compiler is Clang 7.0.
In M2
, I know auto tmp = __VA_ARGS__;
is illegal because decltype(__VA_ARGS__)
is void
. However, I have used if constexpr
, so to me, the compiler should ignore the illegal branch.
Is this comforming to the C++17?