[LLVMbugs] [Bug 7196] New: sizeof member doesn't work in enum initializer

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Sat May 22 04:37:05 PDT 2010


http://llvm.org/bugs/show_bug.cgi?id=7196

           Summary: sizeof member doesn't work in enum initializer
           Product: clang
           Version: trunk
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Keywords: compile-fail
          Severity: normal
          Priority: P
         Component: C++
        AssignedTo: unassignedclangbugs at nondot.org
        ReportedBy: jbytheway+llvm at gmail.com
                CC: llvmbugs at cs.uiuc.edu, dgregor at apple.com


The following C++ code works fine with g++, but gets a compile error with
clang:

=======
struct A {
  int a;

  void f() {
    char i[sizeof(a)]; // Works fine
    enum { x = sizeof(i) }; // Works fine
    enum { y = sizeof(a) }; // Compile error
  }
};

int main() {
  return 0;
}
=======

It yields "error: invalid use of nonstatic data member 'a'".

I haven't looked at the standard in detail, but I'm pretty sure this should be
possible.  In particular it's possible to get at the same value indirectly by
first defining a local variable and taking the size of that, as demonstrated
above.

This issue arose because I had code using BOOST_MPL_ASSERT_RELATION to check
the size of a member, which expands to something assigning the asserted
relation to an enum value.  The above example is simplified from that.

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list