Skip to content

[BUG] Documentation of this/that copy/move ctor/assignment is very confusing and needs significant improvements #1398

Open
@Xeverous

Description

@Xeverous

This is more of a suggestion than a bug but I see your suggestion template is aimed at language features so I write this issue as a bug because I think most readers won't be able to make use of mentioned docs effectively or at all.

The issue
IMO the docs about RAII (https://hsutter.github.io/cppfront/cpp2/types/) are a mess. I'm fairly versed in this stuff yet I find it very unintuitive to write any special member function in Cpp2 and understand the concepts in new syntax. All tried on cppfront built from 5aa32ae.

  1. The docs start with describing this, then go about virtual and inheritance stuff and then back to RAII but in the form of operator= and that. IMO virtual/inheritance stuff should be at the bottom. The split of this and that sections with intermediate less-related section makes it hard to read and creates unnecessary cognitive burden.

  2. Some of provided examples do not work. The first section says "out this: Writing myfunc: (out this /*...*/) defines a Cpp1 constructor... and more. (See below.)" yet when I try to compile anything like myfunc: (out this) or myfunc: (out this, y: std::string) I get a fairly unclear error "error: a function with an 'out this' parameter must be a constructor" - I just tried to write a constructor as the docs say and it is not one?

  3. Some of provided examples do not work. The part about destructors in the first section is just incorrect. It says "move this: Writing myfunc: (move this /*...*/) defines a Cpp1 &&-qualified member function, or if there are no additional parameters it defines the destructor." but when I try dtor: (move this) I'm getting auto dtor() && -> void, not a real dtor.

  4. There are 2 ways to write a destructor (according to documentation): myfunc: (move this) according to this section (doesn't work as in 3)) and operator=: (move this) according to that section (this one is correct).

  5. I can easily generate some nonsense: myfunc: (this, move that) produces auto myfunc(X&& that) const& -> void with notable const&-qualifier and && parameter. This is valid C++ but pretty much useless code.

  6. The infographic about operator= generation is awesome but IMO its value is diminished by the lack of consistent examples: many special member functions are explained (I guess incorrectly?) on myfunc, not operator=.

My suggestions:

  • merge this and that sections into one
  • put virtual/inheritance stuff after all RAII stuff
  • make a cheatsheet of all common functions (static, const&-member, &-member, &&-member, ctor, converting ctor, copy/move ctor/assignment, dtor) (how to write, respective current C++ and whether they generate more functions)
  • provide canonical examples of rule-of-zero class with fancy converting ctor/assignment, rule-of-cpp2 copyable class and rule-of-cpp2 moveable class

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions