Improve docs & test for #pragma clang attribute's any clause; NFC

There was some confusion during the discussion of a patch as to whether
`any` can be used to blast an attribute with no subject list onto
basically everything in a program by not specifying a subrule. This
patch adds documentation and tests to make it clear that this situation
is not supported and will be diagnosed.
This commit is contained in:
Aaron Ballman 2021-11-17 08:20:52 -05:00
parent 8d77555b12
commit 3874277f41
2 changed files with 8 additions and 1 deletions

View file

@ -3798,7 +3798,8 @@ Multiple match rules can be specified using the ``any`` match rule, as shown
in the example above. The ``any`` rule applies attributes to all declarations
that are matched by at least one of the rules in the ``any``. It doesn't nest
and can't be used inside the other match rules. Redundant match rules or rules
that conflict with one another should not be used inside of ``any``.
that conflict with one another should not be used inside of ``any``. Failing to
specify a rule within the ``any`` rule results in an error.
Clang supports the following match rules:

View file

@ -204,3 +204,9 @@ _Pragma("clang attribute pop");
#pragma clang attribute pop
#pragma clang attribute push([[clang::no_destroy]], apply_to = any(variable(is_parameter), variable(unless(is_parameter))))
#pragma clang attribute pop
// We explicitly do not wish to allow users to blast an attribute to everything
// using an unconstrained "any", so "any" must have a valid argument list.
#pragma clang attribute push([[clang::uninitialized]], apply_to=any) // expected-error {{expected '('}}
#pragma clang attribute push([[clang::uninitialized]], apply_to = any()) // expected-error {{expected an identifier that corresponds to an attribute subject rule}}
// NB: neither of these need to be popped; they were never successfully pushed.