Skip to content

[expr.const]/2.11 CWG 2186: "Preceding" is unclear #2307

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
xskxzr opened this issue Aug 23, 2018 · 4 comments
Closed

[expr.const]/2.11 CWG 2186: "Preceding" is unclear #2307

xskxzr opened this issue Aug 23, 2018 · 4 comments
Labels
cwg Issue must be reviewed by CWG. not-editorial Issue is not deemed editorial; the editorial issue is kept open for tracking.

Comments

@xskxzr
Copy link

xskxzr commented Aug 23, 2018

[expr.const]/2.11:

An expression e is a core constant expression unless the evaluation of e, following the rules of the abstract machine, would evaluate one of the following expressions:

  • ...
  • an id-expression that refers to a variable or data member of reference type unless the reference has a preceding initialization and either
    • it is initialized with a constant expression or
    • its lifetime began within the evaluation of e;

It's unclear what "preceding" means. It may either mean the initialization happens before the evaluation of the id-expression, or mean the initialization occurs before the id-expression in lexical order.

According to this example in cppreference:

struct S {
    static const int c;
};
const int d = 10 * S::c; // not a constant expression: S::c has no preceding
                         // initializer, this initialization happens after const
const int S::c = 5;      // constant initialization, guaranteed to happen first

It seems "preceding" means the latter, but consider:

constexpr int f(const int &i)
{
    return i;
}

constexpr int j = f(0);

Here f(0) is obviously a constant expression, but the initialization of i does not occur before return i; in lexical order.

I think it makes more sense to say:

  • an id-expression that refers to a variable or data member of reference type unless either
    • the reference has a preceding initialization, initialized with a constant expression or
    • its lifetime began within the evaluation of e;
@cpplearner
Copy link
Contributor

I don't think this is editorial, and there is already CWG 2186.

@jensmaurer jensmaurer added cwg Issue must be reviewed by CWG. not-editorial Issue is not deemed editorial; the editorial issue is kept open for tracking. labels Sep 2, 2018
@jensmaurer jensmaurer changed the title [expr.const]/2.11 "Preceding" is unclear [expr.const]/2.11 CWG 2186: "Preceding" is unclear Sep 4, 2018
@frederick-vs-ja
Copy link
Contributor

frederick-vs-ja commented Jul 30, 2024

This issue is now mute moot. The first "preceding" in N4659 [expr.const] was removed by P0595R2, and the second was removed by P2280R4.

I believe the meaning is clear enough now, and both this issue and CWG2186 can be closed. @jensmaurer

@jensmaurer
Copy link
Member

off-topic: "mute" and "moot" are different things...

@jensmaurer
Copy link
Member

Closed CWG2186.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cwg Issue must be reviewed by CWG. not-editorial Issue is not deemed editorial; the editorial issue is kept open for tracking.
Projects
None yet
Development

No branches or pull requests

4 participants