[llvm-bugs] [Bug 43470] New: shared_ptr<T[]> doesn't work as c++17 says it should.

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Sep 26 11:45:58 PDT 2019


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

            Bug ID: 43470
           Summary: shared_ptr<T[]> doesn't work as c++17 says it should.
           Product: libc++
           Version: unspecified
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: All Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: jorg.brown at gmail.com
                CC: llvm-bugs at lists.llvm.org, mclow.lists at gmail.com

Consider this simple code:

#include <memory>

const uint32_t* start(std::shared_ptr<const uint32_t[]> smart_array) {
    return smart_array.get();
}

This compiles when using libstdc++ : https://godbolt.org/z/cKHZnl

But not under libc++ : https://godbolt.org/z/pDGSS5

The error I get is:

cannot initialize return object of type 'const uint32_t *' (aka 'const unsigned
int *') with an rvalue of type 'std::__1::shared_ptr<unsigned int
const[]>::element_type *' (aka 'unsigned int const (*)[]')

    return smart_array.get();

           ^~~~~~~~~~~~~~~~~

And speaking of element_type, that may be the fundamental underlying problem. 
In C++17, the type referred to by shared_ptr<T>::element_type changed from:

  T

to:

  std::remove_extent_t<T>

-- 
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/20190926/4a9e1292/attachment.html>


More information about the llvm-bugs mailing list