cplusplus / cplusplus/draft

Clarify that direct-initialized, copy-initialized from E

Open
#4,582 12 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Presumably, "direct-initialized from E" and "copy-initialized from E" should be distinguishable with direct-initialization and copy-initialization. The initialization might be considered as an expression, as per

If a language construct is defined to produce an implicit call of a function, a use of the language construct is considered to be an expression for the purposes of this definition. Conversions applied to the result of an expression in order to satisfy the requirements of the language construct in which the expression appears are also considered to be part of the full-expression. For an initializer, performing the initialization of the entity (including evaluating default member initializers of an aggregate) is also considered part of the full-expression.

I mean that an initialization has been a recipe(comprises the function will be called, if any) whose evaluation will initialize the destination object. However, direct(copy)-initialized from E might be a bit different.

There are many such a usage in the standard, such as
expr.static.cast#4

Otherwise, the result object is direct-initialized from E

dcl.dcl#dcl.init.aggr-5

Otherwise, if the element is not a reference, the element is copy-initialized from an empty initializer list

So, what's the appearance of form here for copy-initialize or direct-initialize respectively? In other words, if we say that an entity t is direct-initialized from an expression E, what's the form?

T t(E); // #1
T t{E}; //#2

Does it refer to #1 or #2? Similarly, when we say that an entity t is copy-initialized from an expression E, what's the form?

T t = E; //#3
T t = {E};  //#4

It does not specify in the standard.

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

Start by reading the cited [expr.static.cast#4] and [dcl.dcl#dcl.init.aggr-5] clauses, then compare the direct- and copy-initialization forms shown in the issue. Clarify whether the standard's phrases identify a particular syntactic form or describe an initialization operation, and update the relevant wording once the distinction is resolved.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
documentation
Issue type
Documentation
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.