cplusplus / CWG

Core Working Group
23 stars 7 forks source link

[expr.context] p2 The materialization of a discarded glvalue expression of volatile type isn't obeyed by implementations #431

Closed xmh0511 closed 1 year ago

xmh0511 commented 1 year ago

Full name of submitter (unless configured in github; will be published with the issue): Jim X

struct A{
    A(){}
    A(A volatile&){
        std::cout<<"copy\n";
    }
};
int main(){ 
  volatile A a;
  a;
}

According to [expr.context] p2 and [conv.lval] p3, the invocation of the constructor A(A volatile&) should be observable. However, no major implementations do this.

I tried to open an issue for Clang and the feedback is

It's worth noting that no C++ compiler does this: https://godbolt.org/z/MaafjMPKG (MSVC can't execute on CE, but I tested locally and the output was start\ndone\n as with the others), so there's not strong motivation for change. WG21 could change the standard to match reality if someone wanted to write the paper.

Relevant issue https://github.com/llvm/llvm-project/issues/52999.

Suggested Resolution

Do we need to insist on this feature or change the relevant wording to match the behavior of implementations?

jensmaurer commented 1 year ago

I think the wording in the standard is clear here, so I can't see a defect. Did C++98 say the same thing? I think it did, although we didn't have "discarded-value expressions" back then.

xmh0511 commented 1 year ago

I think the wording in the standard is clear here, so I can't see a defect. Did C++98 say the same thing? I think it did, although we didn't have "discarded-value expressions" back then.

I think the wording is clear enough. The question is that all implementations do not support this feature. See the linked issue.

jensmaurer commented 1 year ago

CWG1383 made it clear (by adding a note) what the committee intended:

Discarded-value expressions apply to class types, which will be ill-formed if there is no volatile copy constructor with which to initialize the temporary.

I think CWG has spoken on this issue, and a change in direction (even if motivated by a deliberate choice of non-conformance by implementations) needs a paper to EWG.

frederick-vs-ja commented 12 months ago

I think the wording in the standard is clear here, so I can't see a defect. Did C++98 say the same thing? I think it did, although we didn't have "discarded-value expressions" back then.

The wording was originally added by CWG1054. Anyway, I don't think we should revert it.