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

[intro.execution] Is it possible to clarify the second bullet for immediate subexpressions #4525

Open
xmh0511 opened this issue Feb 25, 2021 · 5 comments

Comments

@xmh0511
Copy link
Contributor

xmh0511 commented Feb 25, 2021

As stated in the definition for immediate subexpressions

The immediate subexpressions of an expression E are

  • [...]
  • any function call that E implicitly invokes

Does it refer to the implicit function call that appears in the lexically part of the expression E or any such function call invoked when evaluating the expression E? I mean, in the following two examples

class Test{
  Test(){}
  ~Test(){}
  int a;
};
int main(){
   Test{}.a; // this expression will implicitly invoke the constructor and destructor of class `Test`
}

In this example, these implicitly invoked function calls appear in the lexically part of the expression Test{}.a.

As a contrast, see the second example

class Test{
  Test(){}
  ~Test(){}
  int a;
};
void fun(){
  Test t{};
}
int main(){
  fun();
}

In this example, evaluate the postfix-expression, namely the function call fun(), will implicitly invoke the constructor and destructor of class T which appear in its function body.

It's unclear what's the intent of the bullet second. These two kinds of understanding have a large difference.

@jensmaurer jensmaurer changed the title Is it possible to clarify the second bullet for immediate subexpressions [intro.execution] Is it possible to clarify the second bullet for immediate subexpressions Mar 9, 2021
@xmh0511
Copy link
Contributor Author

xmh0511 commented Mar 27, 2021

@jensmaurer Please examine the conclusion. It seems that in the most major implementations, they consider such an implicitly call as the constructs that appear in the lexical part that corresponds to the expression E instead of these functions that would be dynamically invoked by E. It could infer from [except.spec#6.6]. If were that, then the following cases would print false.

#include <iostream>
struct A{
    A() noexcept(false){
    }
};
void fun() noexcept(true){
    A a{};  // initialization for `a` implicitly invokes A::A()
}
int main(){
  std::cout<< noexcept(fun());
}

But it's not true, the result indicates the expression fun() is not potentially-throwing.

So, my conclusion is that

The immediate subexpressions of an expression E are

  • any function call that E implicitly invokes, which is the part of the full-expression of E

This modification could restrict that these function call should be lexical appears with E rather than dynamically invoked by E

@jensmaurer
Copy link
Member

jensmaurer commented Mar 27, 2021

Yes, "immediate subexpression" is intended on the almost-syntax level.

@xmh0511
Copy link
Contributor Author

xmh0511 commented Mar 27, 2021

Yes, "immediate subexpression" is intended on the almost-syntax level.

So, I thik the sentence "which is the part of the full-expression of E" would help to state that meaning.

@jensmaurer
Copy link
Member

It would not, because we use "subexpression" in the definition of "full-expression", thus the definition would become circular. Not good.

@xmh0511
Copy link
Contributor Author

xmh0511 commented Mar 27, 2021

It would not, because we use "subexpression" in the definition of "full-expression", thus the definition would become circular. Not good.

Could we say "which is lexical". Or any other wording as long as that meaning could be read. In addition, AFAIK, it seems there's no conflict if we use full-expression in that sentence. That means, such an implicitly call is never a full-expression. That approach is merely a bit obscure as you said it becomes circular.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants