C++20哪里禁止sizeof...T(不带括号)
Where does C++20 prohibit sizeof...T (without parentheses)
g++ 和 clang++ 都拒绝在参数未加括号时使用 sizeof...
。例如,以下代码被拒绝:
template<typename... T> auto packsize = sizeof...T;
$ g++ -std=c++20 -ggdb -O -Wall -Werror -c -o z.o z.cc
z.cc:1:50: error: 'sizeof...' argument must be surrounded by parentheses [-fpermissive]
1 | template<typename... T> auto packsize = sizeof...T;
| ^
$ clang++ -std=c++20 -ggdb -O -Wall -Werror -c -o z.o z.cc
z.cc:1:50: error: missing parentheses around the size of parameter pack 'T'
template<typename... T> auto packsize = sizeof...T;
^
()
1 error generated.
CPPreference.org also seems to require parentheses around T
. However, such a restriction does not appear in any of the obvious places in the C++20 standard, e.g., the discussion of sizeof... or the discussion of pack expansions。但是,标准中的所有非规范示例都包含括号。
我的问题:在 C++20 中,哪种规范语言禁止将 sizeof...
与未加括号的标识符一起使用?
语法要求:
unary-expression:
...
sizeof
...
(
identifier )
...
g++ 和 clang++ 都拒绝在参数未加括号时使用 sizeof...
。例如,以下代码被拒绝:
template<typename... T> auto packsize = sizeof...T;
$ g++ -std=c++20 -ggdb -O -Wall -Werror -c -o z.o z.cc
z.cc:1:50: error: 'sizeof...' argument must be surrounded by parentheses [-fpermissive]
1 | template<typename... T> auto packsize = sizeof...T;
| ^
$ clang++ -std=c++20 -ggdb -O -Wall -Werror -c -o z.o z.cc
z.cc:1:50: error: missing parentheses around the size of parameter pack 'T'
template<typename... T> auto packsize = sizeof...T;
^
()
1 error generated.
CPPreference.org also seems to require parentheses around T
. However, such a restriction does not appear in any of the obvious places in the C++20 standard, e.g., the discussion of sizeof... or the discussion of pack expansions。但是,标准中的所有非规范示例都包含括号。
我的问题:在 C++20 中,哪种规范语言禁止将 sizeof...
与未加括号的标识符一起使用?
语法要求:
unary-expression:
...
sizeof
...
(
identifier)
...