gpt4 book ai didi

c++ - 应用于类型别名声明的 [[maybe_unused]] 属性的语法

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:50:18 25 4
gpt4 key购买 nike

尝试找出 [[maybe_unused]] 属性的正确语法导致了 following code :

int main()
{
typedef int X; // warning
[[maybe_unused]] typedef int Y; // Ok
using Z = int; // warning
//[[maybe_unused]] using W1 = int; // error: expected ';' before 'using'
//using [[maybe_unused]] W2 = int; // error: expected nested-name-specifier before '[' token
using W3 [[maybe_unused]] = int; // Ok
//using W4 = [[maybe_unused]] int; // error: an attribute list cannot appear here
}

突然之间,它只有在目标类型名称之后才有效。这看起来很奇怪,因为它通常放在前面。这真的是正确的语法还是只是编译器故障?

最佳答案

根据grammar production,这是正确的放置语法:

alias-declaration:
using identifier attribute-specifier-seq = defining-type-id ;

可选的 attribute-specifier-seq 位于标识符之后和 = 之前。

关于c++ - 应用于类型别名声明的 [[maybe_unused]] 属性的语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50222395/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com