Skip to content
Snippets Groups Projects
Commit c56ff5ff authored by Richard Trieu's avatar Richard Trieu
Browse files

Fix defaulted member functions for templated classes.

In some cases, non-special member functions were being marked as being defaulted
in templated classes.  This can cause interactions with later code that expects
the default function to be one of the specific member functions.  Fix the check
so that templated class members are checked the same way as non-templated class
members are.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@282547 91177308-0d34-0410-b5e6-96231b3b80d8
parent c9b94800
Branches
No related tags found
No related merge requests found
......@@ -13850,12 +13850,6 @@ void Sema::SetDeclDefaulted(Decl *Dcl, SourceLocation DefaultLoc) {
CXXMethodDecl *MD = dyn_cast_or_null<CXXMethodDecl>(Dcl);
 
if (MD) {
if (MD->getParent()->isDependentType()) {
MD->setDefaulted();
MD->setExplicitlyDefaulted();
return;
}
CXXSpecialMember Member = getSpecialMember(MD);
if (Member == CXXInvalid) {
if (!MD->isInvalidDecl())
......@@ -13866,6 +13860,8 @@ void Sema::SetDeclDefaulted(Decl *Dcl, SourceLocation DefaultLoc) {
MD->setDefaulted();
MD->setExplicitlyDefaulted();
 
if (MD->getParent()->isDependentType()) return;
// If this definition appears within the record, do the checking when
// the record is complete.
const FunctionDecl *Primary = MD;
......
......@@ -208,3 +208,31 @@ int fn() {
t = true;
}
}
namespace templated_class {
template <typename T>
class X {
X() = default;
X(const X&) = default;
X(X&&) = default;
X &operator=(const X&) = default;
X &operator=(X&&) = default;
~X() = default;
X(T) = default; // expected-error {{only special member functions may be defaulted}}
void Run() = default; // expected-error {{only special member functions may be defaulted}}
};
template <typename T>
X<T>::X() = default; // expected-error {{definition of explicitly defaulted}}
template <typename T>
X<T>::X(const X<T>&) = default; // expected-error {{definition of explicitly defaulted}}
template <typename T>
X<T>::X(X<T>&&) = default; // expected-error {{definition of explicitly defaulted}}
template <typename T>
X<T> &X<T>::operator=(const X<T>&) = default; // expected-error {{definition of explicitly defaulted}}
template <typename T>
X<T> &X<T>::operator=(X<T>&&) = default; // expected-error {{definition of explicitly defaulted}}
template <typename T>
X<T>::~X() = default; // expected-error {{definition of explicitly defaulted}}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment