temporary object with static storage duration materialization regression with -std=c++17 and above?

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

temporary object with static storage duration materialization regression with -std=c++17 and above?

David Blaikie via cfe-dev
For a top-level lvalue reference to const initialized by a prvalue:

const int& ri = 5;

the object with the value `5` is created in the .rodata section with -std=c++14 and below (which is expected) and in .data with -std=c++17 and above.
https://godbolt.org/z/dbnpM9

I don't see any changes between the standards justifying this.

My guess that clang does not adjust the type of the prvalue as described in [dcl.init.ref]/5.2
> If the converted initializer is a prvalue, its type T4 is adjusted to type “cv1 T4” ([conv.qual]) and the temporary materialization conversion is applied.

With a prvalue initializer of a non-reference-compatible type — `const int& ri = 5.0;` — the object is always created in .rodata.
_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev