标签上的[[maybe_unused]]已定义但未使用

问题描述

[[maybe_unused]]似乎不适用于goto标签,但是在g ++上[[maybe_unused]]可以有效并抑制警告。

标准怎么说?我可以假设其他编译器也发生这种情况吗? (如果标准没有这样说)。

#include <iostream>

using namespace std;


template<uint32_t C>
struct Fixed
{
    static constexpr uint32_t Components = C;
    constexpr uint32_t components() const { return Components; }
};
struct Variable
{
    static constexpr uint32_t Components = 0;
    uint32_t c = 3;
    uint32_t components() const { return c; }
};

template<typename T>
void function(T &&t)
{
    if constexpr (T::Components <= 1)
    {
        if constexpr (!T::Components) if (t.components() != 1) goto con;
        cout << "1 component,fixed or not\n";
        goto fin;
    }
[[maybe_unused]] con:     // here it is!
cout << "many components,fixed or not\n";
fin:
cout << "final jobs\n";
}


int main()
{
    function(Fixed<1>{});
    function(Variable{});
    return 0;
}

解决方法

standard states

[可能未被使用]可以应用于类,类型定义名称,变量,非静态数据成员,函数,枚举或枚举的声明。

该列表上没有goto标签,因此它可能未应用此属性。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...