[cfe-dev] Feature request: Don't warn for specified "unknown" attribute

Aaron Ballman via cfe-dev cfe-dev at lists.llvm.org
Tue Apr 16 05:08:48 PDT 2019


On Mon, Apr 15, 2019 at 11:01 PM Justin Bassett via cfe-dev
<cfe-dev at lists.llvm.org> wrote:
>
> The following code will emit a warning with -Wattributes:
>
> [[some_ns::some_attribute]]
> void call_me();
>
> <source>:1:3: warning: unknown attribute 'some_attribute' ignored [-Wunknown-attributes]
> [[some_ns::some_attribute]]
>   ^
>
> However, this warning is very useful for detecting typos of standard attributes. AFAIK, there's no way to turn off the warning just for one attribute, just all of them (-Wno-unknown-attributes).

That's correct, but it's useful beyond just detecting typos. Different
vendors support different sets of attributes and this diagnostic is
how a developer can tell whether Clang is ignoring a given attribute
or not. It can be very difficult to tell the difference between
"parsed and silently ignoring this attribute" and "parsed attribute
and it functions as designed" depending on the attribute without this
diagnostic. For example, in order to tell whether
__attribute__((deprecated)) is supported, you would have to alter code
to see that it's behaving by design; otherwise, the declarations are
just silently marked as deprecated.

> To solve this, I propose that we add the ability to specify attributes to ignore for -Wunknown-attributes. In other words, something like this: '-Wignore-unknown-attribute=some_ns::some_attribute'.

What issue is being solved, though? If the user wishes to ignore a
specific attribute on Clang because it's not known to the
implementation, the better solution is to use the preprocessor to
provide decent fallback behavior for the attribute. This is why
__has_attribute and friends exist. Is there a different problem that
this new warning flag behavior solves?

~Aaron

> There are some alternatives, such as only warning if the edit distance is close to a known attribute, but I think that specifying the known attribute in the build system like this is better, as it will also catch misspellings of [[some_ns::some_attribute]].
>
> Thank you,
> Justin Bassett
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev



More information about the cfe-dev mailing list