[expr.const] "converted expression is a constant expression"
Nobody has claimed this yet.
- Dominant language
- TeX
- Stars
- 221
- Forks
- 813
- Avg merge
- 16h 4m
- Merged PRs (30d)
- 36
Description
Since we define the concept about implicit conversion in [conv]
An expression E can be implicitly converted to a type T if and only if the declaration T t=E; is well-formed, for some invented temporary variable t ([dcl.init]).
The effect of any implicit conversion is the same as performing the corresponding declaration and initialization and then using the temporary variable as the result of the conversion. The result is an lvalue if T is an lvalue reference type or an rvalue reference to function type ([dcl.ref]), an xvalue if T is an rvalue reference to object type, and a prvalue otherwise. The expression E is used as a glvalue if and only if the initialization uses it as a glvalue.
Consider the rule in [expr.const] p10
A converted constant expression of type T is an expression, implicitly converted to type T, where the converted expression is a constant expression and the implicit conversion sequence contains only
Is this equivalent to saying, we model a declaration
T t = E;
the t is the "converted expression"? Is it equivalent to saying, we require the prvalue t shall be a constant expression? Which should first satisfy [expr.const] p5. However, as a prvalue, we do not supply a result object for it, how do we retrospect what would evaluate when evaluating the initialization that occurs in the model declaration? Specifically, in this example
struct A{
constexpr operator bool(){
return true;
}
};
template<bool B>
struct C{};
constexpr A a;
C<a> c; //#1
At #1, a should be a converted constant expression of type bool. The implicit conversion would apply to a, which is equivalent to model a declaration and perform the initialization
bool conv_result = a; // #0 evaluate the initialization will evaluate the "constexpr operator bool"
C<conv_result > c; // #1'
The conv_result is a prvalue, but how do we retrospect the initialization that occurs at #0 when we do not supply a result object to make the initialization evaluate? It seems if we say that
the full-expression of the initialization associated with the converted expression is a constant expression when interpreted as a constant-expression
will make the meaning more consistent with the definition of implicit conversion. I think this is also suitable for glvalue(converted expression).
struct A{
A(){ std::cout<<"abc\n"; }
};
template<A& rf>
struct C{};
A a;
C<a> c;
/*
A& rf = a; // the full-expression of the initialization shall be a constant expression
*/
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The issue centers on [expr.const] p10 and the related [conv] and [dcl.init] wording; start by tracing how the modeled declaration and initialization apply to the examples. Compare the prvalue and glvalue cases, then determine what wording or interpretation is needed to resolve the question. Done means the draft has an agreed, technically consistent treatment.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100