用于自动引用的__attribute__((未使用))
gcc and __attribute__((unused)) for auto references
使用gcc(已测试5.4.0和6.1.1)和-Wall,会对auto_ref的未使用变量发出警告,但不会对其他变量发出警告。Clang不发出任何警告。这对auto来说是不同的吗?要使用变量,为什么?
int main() {
int __attribute__((unused)) int_var_unused = 42;
int int_var = 42;
int& __attribute__((unused)) int_ref = int_var;
auto __attribute__((unused)) auto_var_unused = 42;
auto auto_var = 42;
auto& __attribute__((unused)) auto_ref = auto_var;
return 0;
}
不确定这是否是GCC中的错误,但它是这样工作的
__attribute__((unused)) auto& auto_ref = auto_var;
和像这样
auto& auto_ref __attribute__((unused)) = auto_var;
我猜这个属性从来没有打算放在类型声明和名称之间。在文档中,我主要将第二个版本作为示例。
相关文章:
- 普通环路未使用gcc 4.8.5自动矢量化
- 在更改for循环的第三部分后,未使用for循环结果
- 使用typeid警告未使用的变量
- C++删除未使用的类属性会导致 std::logic_error
- 警告 C4552:">>":未使用表达式的结果
- (SFML)按下键时,播放器构造函数未使用正确的动画进行更新
- 为什么我会收到警告,指出函数已使用但未定义,以及已定义但未使用?
- 如果我想链接静态库并删除未使用的符号.txt我应该如何处理 Cmakelist
- 可视化C++载体:未使用的容量
- GCC 中 __attribute__((未使用)) 和 __attribute((未使用)) 之间的区别
- 循环访问还包含未使用元素的字符串数组
- Q维德格特关闭事件(..)未使用 QProcess::terminate() 调用
- Visual Studio "fatal error LNK1104: cannot open file"未使用或包含的库
- G++ 编译器是否在未使用返回值的情况下将 constexpr 函数视为常规函数?
- 链接器输入文件未使用,因为链接未完成,我无法获得.o
- 未使用的C++未优化的静态成员函数/变量
- 仅当一个参数中未使用 std::function 时,模板函数替换才有效
- 如何控制或优化或删除或释放 UNION 中未使用的内存
- 未使用的 asm() 在不受支持的体系结构上的行为
- isPalindrome不显示输出,isPalindrome函数未使用字符串输入作为字符串参数进行测试