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

            Bug ID: 27221
           Summary: member function of template instantiated even though
                    only declaration is needed
           Product: clang
           Version: unspecified
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++11
          Assignee: unassignedclangb...@nondot.org
          Reporter: rb...@eudoxos.de
                CC: dgre...@apple.com, llvm-bugs@lists.llvm.org
    Classification: Unclassified

This code fails to compile:

template<typename T>
struct X
{
  X(X&&) { static_assert(sizeof(T) < 1, "Intentional Failure"); }
};

auto impl() -> X<int>;    
auto test() -> decltype(impl())
{
  return impl();
}

int main()
{
  test();
}

My understanding is that it should compile just fine. I admit, I started a
discussion on stackoverflow for this (see
http://stackoverflow.com/questions/36371571/clang-and-gcc-vs-msvc-and-icc-is-a-static-assert-in-the-copy-move-constructor-r)

Citing from the answer I deem correct:

Copy elision requires declaration of copy/move constructors but doesn't require
definition.
Member function definitions of templates are not instantiated unless their
definitions are required.
If a definition is not instantiated it cannot be tested for being ill-formed.
References:

14.7.1.1 …The implicit instantiation of a class template specialization causes
the implicit instantiation of the declarations, but not of the definitions,
default arguments, or exception-specifications of the class member functions…

14.7.1.2 Unless a member of a class template… has been explicitly instantiated
or explicitly specialized, the specialization of the member is implicitly
instantiated when the specialization is referenced in a context that requires
the member definition to exist…

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to