【发布时间】:2016-08-31 10:04:31
【问题描述】:
将 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;
}
【问题讨论】: