https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116529

            Bug ID: 116529
           Summary: Construction of unique_ptr with reference type is
                    rejected because of auto_ptr constructor
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: luigighiron at gmail dot com
  Target Milestone: ---

When constructing a unique_ptr with a reference type an error will occur in the
libstdc++ implementation due to the auto_ptr constructor attempting to form a
pointer to the reference type. For example:

#include<memory>
int main(){
    struct deleter{
        using pointer=int*;
        void operator()(pointer p)const{
            delete p;
        }
    };
    std::unique_ptr<int&,deleter>u(new int);
}

libstdc++ rejects this program, libc++ and MSVC's STL allow it (when compiling
with C++17 or newer). The auto_ptr constructor was removed in C++17 along with
the rest of auto_ptr, this means that there shouldn't be any restrictions on
using a reference type when constructing a unique_ptr. I haven't seen any
restrictions on using a unique_ptr with a reference type so I assume that this
is OK (since C++17).

Reply via email to