]> granicus.if.org Git - clang/commitdiff
Per [dcl.fct.def.default]p1, don't allow variadic special members to be defaulted.
authorRichard Smith <richard-llvm@metafoo.co.uk>
Fri, 7 Dec 2012 02:10:28 +0000 (02:10 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Fri, 7 Dec 2012 02:10:28 +0000 (02:10 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@169574 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDeclCXX.cpp
test/CXX/dcl.decl/dcl.fct.def/dcl.fct.def.default/p1.cpp [new file with mode: 0644]

index 64895d75b5a1f5ce9ad6742930b4109d0f93b4b8..88cc0aa47261953c0a29303d65f925fca75660ac 100644 (file)
@@ -4223,6 +4223,10 @@ void Sema::CheckExplicitlyDefaultedSpecialMember(CXXMethodDecl *MD) {
     Diag(MD->getLocation(), diag::err_defaulted_special_member_params)
       << CSM << MD->getSourceRange();
     HadError = true;
+  } else if (MD->isVariadic()) {
+    Diag(MD->getLocation(), diag::err_defaulted_special_member_variadic)
+      << CSM << MD->getSourceRange();
+    HadError = true;
   }
 
   const FunctionProtoType *Type = MD->getType()->getAs<FunctionProtoType>();
diff --git a/test/CXX/dcl.decl/dcl.fct.def/dcl.fct.def.default/p1.cpp b/test/CXX/dcl.decl/dcl.fct.def/dcl.fct.def.default/p1.cpp
new file mode 100644 (file)
index 0000000..e3e19e1
--- /dev/null
@@ -0,0 +1,26 @@
+// RUN: %clang_cc1 -verify %s -std=c++11
+
+// A function that is explicitly defaulted shall
+struct A {
+  // -- be a special member function,
+  A(int) = default; // expected-error {{only special member functions may be defaulted}}
+
+  // -- have the same declared function type as if it had been implicitly
+  //    declared
+  void operator=(const A &) = default; // expected-error {{must return 'A &'}}
+  A(...) = default; // expected-error {{cannot be variadic}}
+  A(const A &, ...) = default; // expected-error {{cannot be variadic}}
+
+  //    (except for possibly differing ref-qualifiers
+  A &operator=(A &&) & = default;
+
+  // FIXME:
+  //    and except that in the case of a copy constructor or copy assignment
+  //    operator, the parameter type may be "reference to non-const T")
+  A(A &) = default; // FIXME: expected-error {{must be defaulted outside the class}}
+  A &operator=(A &) = default; // FIXME: expected-error {{must be defaulted outside the class}}
+
+  // -- not have default arguments
+  A(double = 0.0) = default; // expected-error {{cannot have default arguments}}
+  A(const A & = 0) = default; // expected-error {{cannot have default arguments}}
+};