r282555 - Revert r282547 and add test to show correct behavior.

Richard Trieu via cfe-commits cfe-commits at lists.llvm.org
Tue Sep 27 16:44:08 PDT 2016


Author: rtrieu
Date: Tue Sep 27 18:44:07 2016
New Revision: 282555

URL: http://llvm.org/viewvc/llvm-project?rev=282555&view=rev
Log:
Revert r282547 and add test to show correct behavior.

Modified:
    cfe/trunk/lib/Sema/SemaDeclCXX.cpp
    cfe/trunk/test/SemaCXX/cxx0x-defaulted-functions.cpp

Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=282555&r1=282554&r2=282555&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Tue Sep 27 18:44:07 2016
@@ -13850,6 +13850,12 @@ void Sema::SetDeclDefaulted(Decl *Dcl, S
   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())
@@ -13860,8 +13866,6 @@ void Sema::SetDeclDefaulted(Decl *Dcl, S
     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;

Modified: cfe/trunk/test/SemaCXX/cxx0x-defaulted-functions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/cxx0x-defaulted-functions.cpp?rev=282555&r1=282554&r2=282555&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/cxx0x-defaulted-functions.cpp (original)
+++ cfe/trunk/test/SemaCXX/cxx0x-defaulted-functions.cpp Tue Sep 27 18:44:07 2016
@@ -209,30 +209,29 @@ int fn() {
 }
 }
 
-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}}
+namespace dependent_classes {
+template <bool B, typename X, typename Y>
+struct conditional;
+
+template <typename X, typename Y>
+struct conditional<true, X, Y> { typedef X type; };
+
+template <typename X, typename Y>
+struct conditional<false, X, Y> { typedef Y type; };
+
+template<bool B> struct X {
+  X();
+
+  // B == false triggers error for = default.
+  using T = typename conditional<B, const X &, int>::type;
+  X(T) = default;  // expected-error {{only special member functions}}
+
+  // Either value of B creates a constructor that can be default
+  using U = typename conditional<B, X&&, const X&>::type;
+  X(U) = default;
+};
+
+X<true> x1;
+X<false> x2; // expected-note {{in instantiation}}
+
 }




More information about the cfe-commits mailing list