How to require a semicolon after a macro
I use enum {}
at the end of a macro to force a semicolon.
This works both inside and outside classes and functions.
This approach does not pollute any namespaces and does not generate any code.
Similar to @thomas-eding 's solution, you can put static_assert(true, "")
at the end of a macro to require a semicolon.
This works both inside and outside classes and functions.
And it does not pollute any namespaces and does not generate any code.
You can add a function declaration at the end of the macro:
#define TESTSUITE(name) \
//... \
void ANONYMOUS_FUNCTION()
Demo
The function name doesn't even have to be different across different TESTSUITE
macros. It's sufficient if it's just not used anywhere else so it doesn't participate in any overloading.