C++03 mode ignores the arg in [[attribute(arg)]] (original) (raw)
https://godbolt.org/z/aPKq1sKPT[[gnu::assume_aligned(4)]] static void *g() { return p; }
In -std=c++11 mode, this code is accepted and works as expected. In -std=c++03 mode, it seems to ignore the (4) argument for some reason, and I get an error:
<source>:5:3: error: 'assume_aligned' attribute takes at least 1 argument
5 | [[gnu::assume_aligned(4)]] static void *g() { return p; }
| ^
@philnik777 I think you enabled attributes in 874217f; is there something missing to enable attributes with arguments?
The problem is these lines in ParseCXX11AttributeArgs.
// If the attribute isn't known, we will not attempt to parse any
// arguments.
if (Form.getSyntax() != ParsedAttr::AS_Microsoft &&
!hasAttribute(LO.CPlusPlus ? AttributeCommonInfo::Syntax::AS_CXX11
: AttributeCommonInfo::Syntax::AS_C23,
ScopeName, AttrName, getTargetInfo(), getLangOpts())) {
This is reusing the return code of hasAttribute to ask whether the attribute is recognized (a boolean). But the machine-generated code in AttrHasAttributeImpl.inc uses the return code to say what __has_cpp_attribute should be set to (an int), and invariably returns 0 in C++03 mode. https://godbolt.org/z/casKPfdez
} else if (ScopeName == "gnu") {
return llvm::StringSwitch<int>(Name)
[...]
.Case("assume_aligned", LangOpts.CPlusPlus11 ? 1 : 0)
That file is generated by clang/utils/TableGen/ClangAttrEmitter.cpp. Maybe a change is needed in that generator?