[dcl.attr.nodiscard]/2 says:
A nodiscard
call is a function call expression that calls a function previously declared nodiscard
, or whose return type is a possibly cv-qualified class or enumeration type marked nodiscard
.
The return type of the function is DiscardableResult
. This type is not marked nodiscard
, as defined in [dcl.attr.grammar]/5:
Each attribute-specifier-seq is said to appertain to some entity or statement, identified by the syntactic context where it appears (Clause 9, Clause 10, Clause 11). If an attribute-specifier-seq that appertains to some entity or statement contains an attribute or alignment-specifier that is not allowed to apply to that entity or statement, the program is ill-formed. If an attribute-specifier-seq appertains to a friend declaration (14.3), that declaration shall be a definition. No attribute-specifier-seq shall appertain to an explicit instantiation (17.7.2).
Emphasis added.
There is no attribute in the "syntactic context" of DiscardableResult
. Therefore, no attribute "appertains" to this entity.
Attributes are not inherited.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…