<html>
<head>
<base href="http://llvm.org/bugs/" />
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW --- - accessing an element of `constexpr static array` inaccurately treated as ODR-usage"
href="http://llvm.org/bugs/show_bug.cgi?id=19643">19643</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>accessing an element of `constexpr static array` inaccurately treated as ODR-usage
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>3.4
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>C++11
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>filip.roseen@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>dgregor@apple.com, llvmbugs@cs.uiuc.edu
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>Created <span class=""><a href="attachment.cgi?id=12469" name="attach_12469" title="testcase.cpp">attachment 12469</a> <a href="attachment.cgi?id=12469&action=edit" title="testcase.cpp">[details]</a></span>
testcase.cpp
struct A {
static constexpr int a[] = {1,2,3};
};
int main () {
int value = A::a[0];
}
---------------------------------------------------------
In the above snippet `clang` inaccurately mandates a definition of `A::a`, even
though there is nothing in the snippet that would ODR-use said static data
member.
The matter has been discussed quite thouroghly in both ##c++ (freenode) and
`Lounge<C++>` (stackoverflow) after I brought attention to the matter.
`gcc` happily compiles the snippet, whereas `clang`, inaccuretely, spits out a
diagnostic about "undefined reference".
----------------------------------------------------------
[ Note: standard quotations shortened for readability ]
[basic.def.odr]p2
> An expression is potentially evaluated unless it is an unevaluated
> operand (Clause 5) or a subexpression thereof. A variable whose
> name appears a potentially-evaluated expression is odr-used unless
> it is an object that satisfies the requirement for appearing in a
> constant expression (5.19) and the lvalue-to-rvalue conversion
> (4.1) is immediately applied.
[expr.const]p2
> - an lvalue-to-rvalue conversion (4.1) unless it is applied to
>
> - a glvalue of literal type that refers to a non-volatile
> object defined with `constexpr`, or that refers to a sub-object
> of such an type.
-----------------------------------------------------------------------
`A::a` in testcase.cpp is a literal type, which is also declared as
`constexpr`, and we are accessing a sub-object of this type; `clang` is
therefore wrong to mandate a definition.
-----------------------------------------------------------------------
More about the matter can be read here:
<a href="http://stackoverflow.com/q/23428684/1090079">http://stackoverflow.com/q/23428684/1090079</a></pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>