Does attribute specifier sequence inherit?

前端 未结 1 2044
遥遥无期
遥遥无期 2020-12-09 09:44

Look at this snippet:

struct [[nodiscard]] Result {
};


struct DiscardableResult: Result {
};

Does DiscardableResult have the

相关标签:
1条回答
  • 2020-12-09 10:03

    [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.

    0 讨论(0)
提交回复
热议问题