Skip to content

CWG2852 [class.mem.general] Is a default argument of a class-scope lambda a complete-class context? #449

Description

@zygoloid

Full name of submitter (unless configured in github; will be published with the issue): Richard Smith

Reference (section label): [class.mem.general]/7

Link to reflector thread (if any): None, but GCC bugzilla thread: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111923

Issue description:

[class.mem.general]/7 is overly broad:

A complete-class context of a class (template) is a
(7.1) function body ([dcl.fct.def.general]),
(7.2) default argument ([dcl.fct.default]),
(7.3) default template argument ([temp.param]),
(7.4) noexcept-specifier ([except.spec]), or
(7.5) default member initializer
within the member-specification of the class or class template.

The "within" here appears to cover such things appearing indirectly within the member-specification, such as a default argument or default template argument of a class-scope lambda-expression:

struct X {
  static constexpr auto a = [] (int n = X::n) {};
  static constexpr int n = 5;
};

Similarly, the current rule appears to treat noexcept-specifiers and default arguments appearing as part of all function types in the class body as complete-class context, rather than only those introduced in the declaration of a member or friend function:

struct Y {
  // *noexcept-specifier* is a complete-class context,
  // but presumably was not intended to be.
  void (*p)(int n) noexcept(sizeof(Y) == 1);
};

Suggested resolution:

Change in [class.mem.general]/7:

A complete-class context of a class (template) or class template C is a
— function body ([dcl.fct.def.general]),
— default argument ([dcl.fct.default]) of a function declaration,
— default template argument ([temp.param]),
noexcept-specifier ([except.spec]) of a function declaration, or
— default member initializer, or
— complete-class context of a nested class defined in C, recursively
where the function, template, non-static data member, or nested class is declared by a member-declaration of C. within the member-specification of the class or class template.
[Note 4: A complete-class context of a nested class is also a complete-class context of any enclosing class, if the nested class is defined within the member-specification of the enclosing class. — end note]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions