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: [email protected]
        ReportedBy: [email protected]
                CC: [email protected], [email protected]
    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.
_______________________________________________
LLVMbugs mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs

Reply via email to