OSDN Git Service

PR c++/38701
authorjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 5 Jan 2009 17:52:18 +0000 (17:52 +0000)
committerjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 5 Jan 2009 17:52:18 +0000 (17:52 +0000)
        * decl.c (cp_finish_decl): Clear DECL_INITIAL for invalid
        defaulting.

        PR c++/38702
        * class.c (defaultable_fn_p): Only operator== can be a copy
        assignment operator.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@143081 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/cp/ChangeLog
gcc/cp/class.c
gcc/cp/decl.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/defaulted7.C [new file with mode: 0644]

index 7ffa760..7c5ae83 100644 (file)
@@ -1,3 +1,13 @@
+2009-01-05  Jason Merrill  <jason@redhat.com>
+
+       PR c++/38701
+       * decl.c (cp_finish_decl): Clear DECL_INITIAL for invalid
+       defaulting.
+
+       PR c++/38702
+       * class.c (defaultable_fn_p): Only operator== can be a copy
+       assignment operator.
+
 2009-01-02  Jason Merrill  <jason@redhat.com>
 
        PR c++/38698
index 805e513..8d326f2 100644 (file)
@@ -4147,7 +4147,8 @@ defaultable_fn_p (tree fn)
     }
   else if (DECL_DESTRUCTOR_P (fn))
     return true;
-  else if (DECL_ASSIGNMENT_OPERATOR_P (fn))
+  else if (DECL_ASSIGNMENT_OPERATOR_P (fn)
+          && DECL_OVERLOADED_OPERATOR_P (fn) == NOP_EXPR)
     return copy_fn_p (fn);
   else
     return false;
index 76482d2..2e19fb3 100644 (file)
@@ -5517,7 +5517,10 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p,
       else if (init == ridpointers[(int)RID_DEFAULT])
        {
          if (!defaultable_fn_p (decl))
-           error ("%qD cannot be defaulted", decl);
+           {
+             error ("%qD cannot be defaulted", decl);
+             DECL_INITIAL (decl) = NULL_TREE;
+           }
          else
            DECL_DEFAULTED_FN (decl) = 1;
        }
index d70fac7..38a3105 100644 (file)
@@ -1,3 +1,7 @@
+2009-01-05  Jason Merrill  <jason@redhat.com>
+
+       * g++.dg/cpp0x/defaulted7.C: New test.
+
 2009-01-05  Thomas Koenig  <tkoenig@gcc.gnu.org>
 
        PR fortran/38672
diff --git a/gcc/testsuite/g++.dg/cpp0x/defaulted7.C b/gcc/testsuite/g++.dg/cpp0x/defaulted7.C
new file mode 100644 (file)
index 0000000..97c2925
--- /dev/null
@@ -0,0 +1,12 @@
+// PR c++/38701, 38702
+// { dg-options "-std=c++0x" }
+
+void foo() = default;          // { dg-error "cannot be defaulted" }
+namespace
+{
+  void bar() = default;                // { dg-error "cannot be defaulted" }
+}
+
+enum E { e };
+
+E& operator |= (E&, const E&) = default; // { dg-error "cannot be defaulted" }