The problem is the comma in the capture list.
The preprocessor has an extremely limited understanding of C ++ syntax; it basically performs trivial text replacement. If the comma is not between the matching inner brackets (and not the token part, like a string literal, of course), the preprocessor will consider it as a separator of the macro arguments.
So, the preprocessor thinks that you are calling assert with two arguments [this
and the rest of the record behind the first comma, which gives an error.
You can fix this error using an extra set of parentheses:
int i = -7, j = 7; assert(([i,j](){return i + j;}()));
For standard lovers:
The sequence of preprocessing tokens limited by external sliding brackets makes a list of arguments for the macro function. The individual arguments in the list are separated by a comma in the preprocessing notes, but the preprocessing tokens are separated by comma between the matching inner brackets. If the argument list contains sequences of preprocessing tokens that otherwise act as preprocessor directives 155, the behavior is undefined.
16.3 / 11 in N4140, the emphasis is mine.
source share