<div class="gmail_quote">On Mon, Jun 11, 2012 at 6:27 PM, Suman Kar <span dir="ltr"><<a href="mailto:skarpio@gmail.com" target="_blank">skarpio@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hello,<br>
<br>
I am perusing through N2235 (Generalized Constant Expressions) and was trying<br>
out the example on page 8, namely:<br>
<br>
struct complex {<br>
        constexpr complex(double r, double i) : re(r), im(i) { }<br>
        constexpr double real() { return re; }<br>
        constexpr double imag() { return im; }<br>
private:<br>
        double re;<br>
        double im;<br>
};<br>
constexpr complex I(0, 1); // OK -- literal complex<br>
<br>
constexpr double d = I.real(); // added by me<br>
<br>
I generated the assembler output with my clang++ build:<br>
<br>
$ /d/llvm_workspace/build/Debug+Asserts/bin/clang++ -v<br>
clang version 3.2 (trunk 157115) (llvm/trunk 157155)<br>
Target: i686-pc-mingw32<br>
Thread model: posix<br>
<br>
and it churned out the following:<br>
<br>
        .data<br>
        .align  8<br>
__ZL1I:<br>
        .quad   0<br>
        .quad   4607182418800017408<br>
<br>
        .align  8<br>
__ZL1d:<br>
        .quad   0<br></blockquote><div><br></div><div>This looks like a backend issue: it appears that we don't support .rodata when targeting i686-pc-mingw32. For i686-linux-gnu, we produce this:</div><div><br></div>
<div><div>        .file   "constexpr.cpp"</div><div>        .type   _ZL1I,@object           # @_ZL1I</div><div>        .section        .rodata,"a",@progbits</div><div>        .align  4</div><div>_ZL1I:</div>
<div>        .quad   0                       # double 0.000000e+00</div><div>                                        #  (0x0)</div><div>        .quad   4607182418800017408     # double 1.000000e+00</div><div>                                        #  (0x3ff0000000000000)</div>
<div>        .size   _ZL1I, 16</div><div><br></div><div>        .type   _ZL1d,@object           # @_ZL1d</div><div>        .align  8</div><div>_ZL1d:</div><div>        .quad   0                       # double 0.000000e+00</div>
<div>                                        #  (0x0)</div><div>        .size   _ZL1d, 8</div><div><br></div><div><br></div><div>        .section        ".note.GNU-stack","",@progbits</div></div><div> </div>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Also, does 3.6.2/3 mandate that static initialization will not occur for objects<br>
with extern linkage?</blockquote><div><br></div><div>3.6.2/3 doesn't mandate anything. Instead, it gives the implementation permission to transform dynamic initialization into static initialization in some circumstances.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> IOW, the following:<br>
<br>
extern constexpr complex I(0, 1); // OK -- literal complex<br>
<br>
will always require dynamic initialization and can thus never be in a<br>
ro-section?</blockquote><div><br></div><div>No, static initialization (in particular, constant initialization) is required here, because the variable is constexpr. Clang (well, LLVM) emits this variable into an RO section on targets where it knows how to do so.</div>
</div>