<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - clang11 does not generate code for `shared_ptr_emplace`"
   href="https://bugs.llvm.org/show_bug.cgi?id=44869">44869</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>clang11 does not generate code for `shared_ptr_emplace`
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>C++2a
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>vittorio.romeo@outlook.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>blitzrakete@gmail.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=23119" name="attach_23119" title="Reproducible example">attachment 23119</a> <a href="attachment.cgi?id=23119&action=edit" title="Reproducible example">[details]</a></span>
Reproducible example

Description:

When creating a `std::shared_ptr` of a variadic template class inside a
coroutine, the compiler fails to generate the methods of the template class 
`__shared_ptr_emplace`, and linking fails.



Links to reproducible example:
<a href="https://gcc.godbolt.org/z/GpqoYi">https://gcc.godbolt.org/z/GpqoYi</a>
<a href="https://wandbox.org/permlink/NRmkf9cnb0eJHgqj">https://wandbox.org/permlink/NRmkf9cnb0eJHgqj</a>



Resulting error:

/tmp/prog-e218f2.o:(.rodata._ZTVNSt3__120__shared_ptr_emplaceI1AIiENS_9allocatorIS2_EEEE[_ZTVNSt3__120__shared_ptr_emplaceI1AIiENS_9allocatorIS2_EEEE]+0x10):
undefined reference to `std::__1::__shared_ptr_emplace<A<int>,
std::__1::allocator<A<int> > >::~__shared_ptr_emplace()'
/tmp/prog-e218f2.o:(.rodata._ZTVNSt3__120__shared_ptr_emplaceI1AIiENS_9allocatorIS2_EEEE[_ZTVNSt3__120__shared_ptr_emplaceI1AIiENS_9allocatorIS2_EEEE]+0x18):
undefined reference to `std::__1::__shared_ptr_emplace<A<int>,
std::__1::allocator<A<int> > >::~__shared_ptr_emplace()'
/tmp/prog-e218f2.o:(.rodata._ZTVNSt3__120__shared_ptr_emplaceI1AIiENS_9allocatorIS2_EEEE[_ZTVNSt3__120__shared_ptr_emplaceI1AIiENS_9allocatorIS2_EEEE]+0x20):
undefined reference to `std::__1::__shared_ptr_emplace<A<int>,
std::__1::allocator<A<int> > >::__on_zero_shared()'
/tmp/prog-e218f2.o:(.rodata._ZTVNSt3__120__shared_ptr_emplaceI1AIiENS_9allocatorIS2_EEEE[_ZTVNSt3__120__shared_ptr_emplaceI1AIiENS_9allocatorIS2_EEEE]+0x30):
undefined reference to `std::__1::__shared_ptr_emplace<A<int>,
std::__1::allocator<A<int> > >::__on_zero_shared_weak()'
clang-11: error: linker command failed with exit code 1 (use -v to see
invocation)



How to reproduce:

Compile the code below with the following line:

/usr/bin/clang++-11 -std=gnu++2a -fcoroutines-ts -stdlib=libc++ -nostdinc++
-isystem/usr/lib/llvm-11/include/c++/v1/ -L/usr/lib/llvm-11/lib/
-Wl,-rpath,/usr/lib/llvm-11/lib test.cpp

Code:

#include <experimental/coroutine>
#include <tuple>

struct task
{
struct promise_type
{
task get_return_object() { return task{}; }
void return_void() {}
std::experimental::suspend_always initial_suspend() { return {}; }
void unhandled_exception() noexcept { std::terminate(); }
std::experimental::suspend_never final_suspend() { return {}; }
};
};

// removing the template fixes the linker error
template<typename Args>
struct A {};

int main()
{
// Using a regular function instead of a coroutine fixes the linker error
#ifdef FIX_1
auto coro = [](auto&& int2dbl) {
std::make_shared<A<int>>();
};
#else
auto coro = [](auto&& int2dbl) -> task {
std::make_shared<A<int>>();
co_return;
};
#endif

// Calling the coroutine directly fixes the linker error
#ifdef FIX_2
coro(A<int>());
#else
auto As = std::make_tuple(10);
std::apply([&](auto& wrapper) { return coro(wrapper); }, As);
#endif
}</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>