https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81513
Bug ID: 81513 Summary: __has_cpp_attribute returns non-zero in C++03 mode, but attributes don't work Product: gcc Version: 7.1.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: proski at gnu dot org Target Milestone: --- Following compiles with "g++ -Wall -std=c++03 test.cpp -o test" and outputs "200809 201603 199711" #include <iostream> int main() { std::cout << __has_cpp_attribute(noreturn) << ' ' << __has_cpp_attribute(maybe_unused) << ' ' << __cplusplus << '\n'; } [[maybe_unused]] doesn't work in C++03 mode in g++. It does work in C++11 mode, despite it being a C++17 feature. In C++11 mode, __cplusplus would be less than __has_cpp_attribute(maybe_unused), yet [[maybe_unused]] would work. With clang-4.0 in C++03 mode, the output is "0 0 199711". I believe GCC should do the same. If attributes are not supported at all, __has_cpp_attribute() should return 0. I want to do following without special casing GCC or older standards: #if defined(__has_cpp_attribute) && __has_cpp_attribute(maybe_unused) #define __maybe_unused [[maybe_unused]] #endif