When should "members" be read to exclude inherited members?

59 views
Skip to first unread message

Edward Catmur

unread,
Oct 6, 2016, 6:03:16 PM10/6/16
to ISO C++ Standard - Discussion
[class.derived]/2:

Unless redeclared in the derived class, members of a base class are also considered to be members of the derived class. Members of a base class other than constructors are said to be 
inherited by the derived class.

But there are plenty of places where "members" (in particular, non-static data members) can only be read as referring solely to immediate (non-inherited) members, e.g. [class.base.init]/2, or [class.ctor]/4:

A defaulted default constructor for class X is defined as deleted if: [...]
  • any non-variant non-static data member of const-qualified type (or array thereof) with no brace-or-equal-initializer does not have a user-provided default constructor [...]
Before the resolution to CWG 1813, this also included [class/7], as discussed here.

And while there are several places (e.g. [basic.lval]/7.8, [class]/8.6) where inherited members are explicitly included, there are also places where inherited members are implicitly included, e.g. [class.copy]/23 (here by implicit contrast to "direct"):

A defaulted copy/move assignment operator for class X is defined as deleted if X has: [...]
  • a non-static data member of const non-class type (or array thereof), or
  • a non-static data member of reference type, or
  • a direct non-static data member of class type M (or array thereof) [...] that cannot be copied/moved [...]
So are we supposed to infer the meaning from context, and if so, how? Or is this a defect that could be resolved by inserting "direct"/"immediate" (the term used in [class.copy]/28) where appropriate?

Richard Smith

unread,
Oct 6, 2016, 7:28:02 PM10/6/16
to std-dis...@isocpp.org
The correct term for members of a class that are not members of a base class is "direct members", but we put the wording change introducing that term into the defaulted comparisons wording, which didn't get moved into the standard, so we're currently using that term without a definition. See http://wg21.link/cwg1860

We should use that term explicitly whenever we don't mean to include base class members, rather than hoping that readers will infer the meaning from context. For obvious cases, I'd be happy to take pull requests to editorially add the missing word "direct".
Reply all
Reply to author
Forward
0 new messages