[LLVMbugs] [Bug 14855] New: clang does not diagnose reference-to-member types

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Tue Jan 8 14:05:08 PST 2013


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

             Bug #: 14855
           Summary: clang does not diagnose reference-to-member types
           Product: clang
           Version: trunk
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++11
        AssignedTo: unassignedclangbugs at nondot.org
        ReportedBy: seth.cantrell at gmail.com
                CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
    Classification: Unclassified


There is no such thing as a reference-to-member type in C++. There is no syntax
for using them, no syntax for initializing them, and normally no syntax for
declaring them.

However with the following type aliases clang is perfectly happy to allow such
types to be created and used to a limited degree:

    template<typename T>
    using ref = T&;

    template<typename T, typename C>
    using mem = T C::;

Clang allows these reference-to-member types to be used like this:

    #include <cstdio>
    #include <type_traits>

    struct S {
        ref<mem<int,S>> x;
    };

    int main() {
        std::printf("%i\n", (int)sizeof(S));

        std::aligned_storage<S>::type X;
    }

Additionally clang permits the mem type alias to be used in ways that it does
not permit for the equivalent member syntax:

    struct S {};

    mem<int, S> foo = 1;

    int S::foo2 = 1; // error

    int main() {
        mem<int, S> foo3 = 3;

        int S::foo4 = 4; // error

        return foo3;
    }

Clang treats these 'member' variables as though they are variables of type T.

    int main() {
        mem<int, S> foo;
        int S::*foo2 = &foo; // error
    }

error: cannot initialize a variable of type 'int S::*' with an rvalue of type
'mem<int, S> *' (aka 'int *')

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