C++中“()”如何将语句转换为表达式?

How does "()" convert statements into expressions in C++?

我有以下代码:

int main() {
    int i=0;
    int j=({int k=3;++i;})+1; // this line
    return 0;
}

编译运行。如果我从 "this line" 中删除 (),则它不会编译。

我很好奇这里应用的是什么语法规则。

{}包含2条语句,最后一条语句表示此代码块的"return"值。那为什么它需要一个额外的 () 对来使这个 return 值可用?

这是一个 statement expression,它是 GCC 特定的扩展。


来自链接参考:

A compound statement enclosed in parentheses may appear as an expression in GNU C. This allows you to use loops, switches, and local variables within an expression.

一个复合语句是一个花括号括起来的语句块。