GCC Newspaper
JULY 29, 2026
Date
/
Architectures
Components
Topics
News & Policy
c++

C++: In attributes expect _Clang namespace rather than __clang__

C++ attribute handling now prefers '_Clang::' over '__clang__::' for compatibility with Clang.

GCC’s C++ frontend now better handles Clang’s attribute namespace syntax for improved compatibility. While Clang’s __clang__ macro means it uses _Clang::__attribute__ internally, GCC will now accept _Clang:: as the preferred namespace and warn if __clang__:: is used. This change also ensures correct behavior for __has_cpp_attribute and __has_attribute when targeting Clang-specific attributes.

In Details

Clang uses _Clang::__attribute__ for its scoped attributes, as __clang__ is a predefined macro. This commit modifies GCC's attribute parsing to recognize _Clang:: as the canonical namespace, mirroring Clang's behavior. It emits a warning for the less-compatible __clang__:: namespace, while __has_cpp_attribute and __has_attribute are adjusted not to canonicalize __clang__ at all, returning 0 for such attributes to avoid misinterpretation. The documentation (extend.texi) is updated accordingly.

For Context
attribute
In C++, a language extension that allows programmers to attach metadata to declarations (like functions, variables, or types). These attributes can influence compiler behavior, code generation, or provide information for static analysis tools.
namespace
A declarative region that provides a scope to the identifiers (names of types, functions, variables, etc.) inside it. This helps in organizing code and preventing naming conflicts.
Clang
A C-family compiler front-end for C, C++, Objective-C, and Objective-C++. It is part of the LLVM project.
__has_cpp_attribute
A C++ preprocessor operator that checks for the availability of a standard C++ attribute.
__has_attribute
A GCC-specific preprocessor operator (also supported by Clang) that checks for the availability of any attribute, whether standard, vendor-specific, or GNU-specific.
Filed Under: c++attributescompatibility