[LLVMbugs] [Bug 19643] New: accessing an element of `constexpr static array` inaccurately treated as ODR-usage

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Fri May 2 12:50:33 PDT 2014


            Bug ID: 19643
           Summary: accessing an element of `constexpr static array`
                    inaccurately treated as ODR-usage
           Product: clang
           Version: 3.4
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++11
          Assignee: unassignedclangbugs at nondot.org
          Reporter: filip.roseen at gmail.com
                CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
    Classification: Unclassified

Created attachment 12469
  --> http://llvm.org/bugs/attachment.cgi?id=12469&action=edit

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

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 ]


  > 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.


  > - 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:

You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20140502/1ddfbd9c/attachment.html>

More information about the llvm-bugs mailing list