[LLVMbugs] [Bug 12866] New: sizeof does not work with member in anonymous union

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Fri May 18 05:39:45 PDT 2012


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

             Bug #: 12866
           Summary: sizeof does not work with member in anonymous union
           Product: clang
           Version: trunk
          Platform: Macintosh
        OS/Version: MacOS X
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++11
        AssignedTo: unassignedclangbugs at nondot.org
        ReportedBy: jonathan.sauer at gmx.de
                CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
    Classification: Unclassified


The following code does not compile with clang r157048:

union Foo {
    int member;
};

struct Bar {
    union {
        int member;
    };
};

template <typename Struct>
constexpr unsigned int memberSize()
{
    return sizeof(Struct::member);
}

static_assert(sizeof(Foo) == sizeof(Foo::member), "");      // Compiles
static_assert(sizeof(Bar) == sizeof(Bar::member), "");      // Does not compile
static_assert(sizeof(Foo) == memberSize<Foo>(), "");        // Compiles
static_assert(sizeof(Bar) == memberSize<Bar>(), "");        // Compiles


This results in:

$ ~/LLVM/build/Release+Asserts/bin/clang++ -v -std=c++11 clang.cpp
clang version 3.2 (trunk 157048)
Target: x86_64-apple-darwin10.8.0
Thread model: posix
[...]
clang.cpp:18:42: error: invalid use of non-static data member 'member'
static_assert(sizeof(Bar) == sizeof(Bar::member), "");      // Does not compile
                                    ~~~~~^~~~~~
clang.cpp:18:53: error: expected unqualified-id
static_assert(sizeof(Bar) == sizeof(Bar::member), "");      // Does not compile
                                                    ^
2 errors generated.


It seems like clang does not find "member" inside the anonymous union in Bar,
except when Bar is hidden behind a template parameter.

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