I have a program with its own smart pointer type derived from std::shared_ptr
. The program compiles fine with the latest Visual Studio 2019 v16.11. But trying to build it in GCC or Clang results in error.
After simplification the code where the compilers diverge is as follows:
#include <memory>
template <typename T>
class MyPtr : public std::shared_ptr<T> {
using base = std::shared_ptr<T>;
public:
using base::operator=;
using base::base;
};
int main() {
MyPtr<int> a = std::make_shared<int>(); //error here
}
GCC emits the error:
conversion from 'std::shared_ptr<int>' to non-scalar type 'MyPtr<int>' requested
Demo: https://gcc.godbolt.org/z/bsxMz96z9
I guess, the program author intent was that
using base::operator=;
using base::base;
would add all constructors and assignment operators from std::shared_ptr
to MyPtr
.
Since both GCC and Clang reject the code, I suspect MSVC is wrong here, but why exactly?