Skip to content

clang incorrectly judges default copy constructor in template class #99749

Open
@Rush10233

Description

@Rush10233

Consider the following code:

template<typename T>
class Box
{
public:
  Box(const Box<int>&)=default;
  //Box(const Box<T>&)=default;
};

The constructor of class Box in line 5 should be a normal user-defined constructor instead of a copy constructor as the parameter list is incompatible(the real copy ctor should be in the form of that in line 6), so it should not be declared as defaulted. Both GCC and MSVC reject the code, but clang accepts it.

MSVC provides the following diagnostic:

example.cpp
<source>(6): error C2610: 'Box<T>::Box(const Box<int> &)': is not a special member function or comparison operator which can be defaulted
<source>(6): note: the template instantiation context (the oldest one first) is
<source>(3): note: while compiling class template 'Box'
Compiler returned: 2

Please see https://godbolt.org/z/EbY3zWKc1

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions