Skip to content

<memory>: shared_ptr comparison (<=>) #3646

@viccpp

Description

@viccpp

Describe the bug
Comparison of std::shared_ptrs fails. See the test case.

Command-line test case

C:\Temp>type repro.cpp
#include<compare>
#include<memory>

int main()
{
    std::shared_ptr<const int> p1;
    std::shared_ptr<void> p2;

    auto cmp = p1 <=> p2;
}

C:\Temp>cl /std:c++20 repro.cpp
Microsoft (R) C/C++ Optimizing Compiler Version 19.35.32215 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

repro.cpp
C:\opt\VC\include\memory(1778): error C2446: '<=>': no conversion from 'void *' to 'const int *'
C:\opt\VC\include\memory(1778): note: Conversion from 'void*' to pointer to non-'void' requires an explicit cast
repro.cpp(9): note: see reference to function template instantiation 'std::strong_ordering std::operator <=><const int,void>(const std::shared_ptr<const int> &,const std::shared_ptr<void> &) noexcept'
 being compiled

Expected behavior
Successful compilation at least.

Additional notes
This fails as well:

 const int *p1;
 void *p2;

 auto cmp = p1 <=> p2;

But both GCC and Clang compile this successfully!

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingcompilerCompiler work involvedfixedSomething works now, yay!

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions