cplusplus / cplusplus/draft

[dcl.fct.default] Incorrect note on `this` in default arguments

Open
#6,558 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

P2-Bug
Dominant language
TeX
Stars
221
Forks
813
Avg merge
16h 4m
Merged PRs (30d)
36

Description

[dcl.fct.default] p8 states:

[Note 5: The keyword this cannot appear in a default argument of a member function; see [expr.prim.this].

class A {
  void f(A* p = this) { }           // error
};

This is incorrect, because the following program is well-formed and the keyword this appears in a default argument:

class A {
  void f(auto = [] {
    struct B { B() { this; } }; // keyword this appeared in a default argument
  }) { }
};

Syntactically, the entire initializer-clause is the default argument, and the this keyword obviously appears inside of it. See [dcl.fct.default] p1

Solution

We could say "cannot directly appear" but this is wishy washy, though correct according to some reader's imaginations.

Wording it in terms of "current class" and whatnot is quite difficult, so maybe we could just say:

Except within the block scope of a lambda-expression, the this keyword cannot ...

It's just a note, so we don't need to make it cover all the cases in all the detail; we just need to make it correct.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Read [dcl.fct.default] p8 and [expr.prim.this], then compare the note with the well-formed lambda example in the issue. Revise the note so it no longer incorrectly prohibits this within a lambda block scope, and confirm the wording remains consistent with the example.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, tex
Domain
documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.