Issue 52999
Summary Discarded value _expression_ of volatile-qualified class type should materialize a temporary object
Labels new issue
Assignees
Reporter xmh0511
    ````cpp
struct A{
    A(){}
    A(A volatile&){
        std::cout<<"copy\n";
    }
};
int main(){ 
  volatile A a;
  a;
}
````
[expr.context] p2
> In some contexts, an _expression_ only appears for its side effects. Such an _expression_ is called a discarded-value _expression_. The array-to-pointer and function-to-pointer standard conversions are not applied. **The lvalue-to-rvalue conversion is applied if and only if the _expression_ is a glvalue of volatile-qualified type and it is one of the following**:
>> - [...]
>> - id-_expression_ ([expr.prim.id]),
>>- [...]
>
> If the (possibly converted) _expression_ is a prvalue, **the temporary materialization conversion is applied**.  
>
> [Note 3: If the _expression_ is an lvalue of class type, it must have a volatile copy constructor to initialize the temporary object that is the result object of the lvalue-to-rvalue conversion. — end note]


[conv.lval] p3
> The result of the conversion is determined according to the following rules:
>> - [...]
>> - Otherwise, if T has a class type, the conversion **copy-initializes the result object from the glvalue**.

Hence, the call of `A(A volatile&)` should be observable.


_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to