[llvm-bugs] [Bug 38257] New: operator& definition causes unexplained error passing pointer-to-member to template parameter

via llvm-bugs llvm-bugs at lists.llvm.org
Sat Jul 21 08:26:41 PDT 2018


https://bugs.llvm.org/show_bug.cgi?id=38257

            Bug ID: 38257
           Summary: operator& definition causes unexplained error passing
                    pointer-to-member to template parameter
           Product: clang
           Version: 6.0
          Hardware: All
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: ambrop7 at gmail.com
                CC: dgregor at apple.com, llvm-bugs at lists.llvm.org

The following C++14 program does not compile even though I think it should and
does with GCC.


template<typename>
class enable;

template<typename T, typename = typename enable<T>::enabled>
void operator&(T, T);

template<typename A, typename B, B A::*>
struct Member {};

template<typename>
struct Dummy {};

template<typename X>
struct Bar {
  struct Y {
    X field;
  };
  using Useless = Member<Y, X, &Y::field>;
};

template<typename>
struct Foo {
  struct Nested;
  using FieldType = Bar<Dummy<Nested>>;
  FieldType foo_member;
};

template<typename T>
struct Foo<T>::Nested : Member<Foo, FieldType, &Foo::foo_member> {};

Foo<void> foo;


The error is:

prog.cpp:29:54: error: no member 'foo_member' in 'Foo<void>'; it has not yet
been instantiated
struct Foo<T>::Nested : Member<Foo, FieldType, &Foo::foo_member> {};
                                                     ^
prog.cpp:18:32: note: in instantiation of member class 'Foo<void>::Nested'
requested here
  using Useless = Member<Y, X, &Y::field>;
                               ^
prog.cpp:25:13: note: in instantiation of template class
'Bar<Dummy<Foo<void>::Nested> >' requested here
  FieldType foo_member;
            ^
prog.cpp:31:11: note: in instantiation of template class 'Foo<void>' requested
here
Foo<void> foo;
          ^
prog.cpp:25:13: note: not-yet-instantiated member is declared here
  FieldType foo_member;
            ^


The following changes allow the program to compile:
- Removing the operator& definition or changing it to operator|. (This seems
very strange to me!)
- Removing the definition of Foo<T>::Nested (while leaving the declaration
within Foo).
- Removing "using Useless = ..." within Bar.

The error indicates that Clang is trying to instantiate Foo<void>::Nested due
to the expression &Y::field. This seems unnecessary to me. I think Dummy<X>
should be instantiatable for any X without needing to instantiate X, and as
such it seems inappropriate that Clang is instantiating Foo<void>::Nested.

-- 
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/20180721/96233674/attachment.html>


More information about the llvm-bugs mailing list