[llvm-bugs] [Bug 27221] New: member function of template instantiated even though only declaration is needed

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Apr 5 09:25:37 PDT 2016


            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: unassignedclangbugs at nondot.org
          Reporter: rbock at eudoxos.de
                CC: dgregor at apple.com, llvm-bugs at 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()

My understanding is that it should compile just fine. I admit, I started a
discussion on stackoverflow for this (see

Citing from the answer I deem correct:

Copy elision requires declaration of copy/move constructors but doesn't require
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: …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… 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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20160405/2cb92ed2/attachment-0001.html>

More information about the llvm-bugs mailing list