Must attribute arguments be exactly as shown in Annex C? #870
Labels
type: clarity
While not technically incorrect, the Standard is potentially confusing
Milestone
Describe the bug
From §5 and §C.1 in the C# 7.x draft, it is not clear whether a conforming implementation has to decorate the standard classes with attributes exactly as specified in Annex C, or whether it can use different values as attribute arguments — for example, adding more AttributeTargets bits to an AttributeUsageAttribute on an attribute class.
Example
§C.1 specifies this type:
Could a conforming implementation use e.g.
AttributeTargets.Parameter | AttributeTargets.Field
instead? If so, would that count as an extension and have to be documented? (Independently of whether the attribute has any compile-time effect when applied to a field.)Expected behavior
Directly specify whether this is allowed.
Additional context
§5 does not mention attributes here:
(If that paragraph were modified to allow changing attribute arguments, the "provided that" condition at the end would not be a problem, as MemberInfo.GetCustomAttributes and Attribute.GetCustomAttributes methods are not listed in Annex C and thus cannot be called by a strictly conforming program.)
§C.1 says that additional attributes are allowed, but does not mention modifications of specified attributes. Also, that text is informative.
Inspired by #858; if C# 10 specifies AttributeTargets.Method on AsyncMethodBuilderAttribute but C# 7.3 does not, and modifications of attribute arguments are not allowed, then it won't be possible for implementations using the same library to comply with both versions of C#, which would be unfortunate.
The text was updated successfully, but these errors were encountered: