simplecpp
simplecpp copied to clipboard
C++20 __VA_OPT__
In forum : https://sourceforge.net/p/cppcheck/discussion/general/thread/2811dc2f3b
It was reported that __VA_OPT__ is not handled.
#include <cstdio>
#define p1(fmt, ...) printf(fmt __VA_OPT__(,) __VA_ARGS__)
void test() {
p1("hello");
p1("%s", "hello");
}
complex examples from (links taken from https://clang.llvm.org/cxx_status.html) http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0306r4.html http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p1042r1.html
#define SDEF(sname, S, ...) S sname __VA_OPT__(= { __VA_ARGS__ })
SDEF(foo, 1);
SDEF(bar, 1, 2, 3);
extern int printf(const char *fmt, ...);
#define LOG(...) \
printf("at line=%d" __VA_OPT__(": "), __LINE__); \
__VA_OPT__(printf(__VA_ARGS__);) \
printf("\n")
LOG();
LOG("All well in zone %n", n);
note I changed SDEF(foo); to SDEF(foo, 1);, the former is not supported by gcc or clang.