https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77419
Bug ID: 77419 Summary: Unconsistent behavior with references& and __attribute__((unused)) Product: gcc Version: 6.1.1 Status: UNCONFIRMED Severity: minor Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: tobias.leibner at googlemail dot com Target Milestone: --- The following code 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; } produces an unused variable warning for auto_ref when compiled with g++ -std=c++11 -Wall, but not for the other variables. I just learned that __attribute__((unused)) is intended to be placed after the variable name, in that case the warning is suppressed as expected. So I am not sure whether this is expected behavior, but it seems to work for everything that is not an auto& variable and also works in clang.