Skip to content
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

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

Open
xskxzr opened this issue Aug 23, 2018 · 1 comment
Open

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

xskxzr opened this issue Aug 23, 2018 · 1 comment
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
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

3 participants