[LLVMbugs] [Bug 19266] New: C++11-style sizeof does not compile in certain cases.

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Thu Mar 27 13:49:12 PDT 2014


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

            Bug ID: 19266
           Summary: C++11-style sizeof does not compile in certain cases.
           Product: clang
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++11
          Assignee: unassignedclangbugs at nondot.org
          Reporter: astellar at ro.ru
                CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
    Classification: Unclassified

Consider this artificial code:

    struct foo
    {
        int bar;
    };

    template <typename T>
    struct A { };

    template <typename T>
    struct B : public A<T>
    {
        void baz()
        {
            enum { count = sizeof(foo::bar) };
        }
    };

    int main(int, char *[])
    {
        B<int>().baz();
        return 0;
    }

clang++ -std=c++11 bug.cpp produces following output:

    bug.cpp:14:36: fatal error: 'foo::bar' is not a member of class 'B<int>'
            enum { count = sizeof(foo::bar) };
                                  ~~~~~^
    bug.cpp:20:14: note: in instantiation of member function 'B<int>::baz'
requested here
        B<int>().baz();

I see this error with both clang 3.4 on Linux and 3.5.r203967 snapshot on
Windows, so I
suppose that it fails in trunk too (can't test it unfortunately). Compilation
does not
fail if:
    - B::baz is turned into static function;
    - enum is moved to struct B's scope;
    - I use sizeof(static_cast<foo*>(0)->bar) instead of sizeof(foo::bar);
    - A and/or B are not template types.

GCC 4.8 compiles this code without errors.

-- 
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/20140327/8fe0245c/attachment.html>


More information about the llvm-bugs mailing list