This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
C++ PATCH for c++/38701 and 38702
- From: Jason Merrill <jason at redhat dot com>
- To: gcc-patches List <gcc-patches at gcc dot gnu dot org>
- Date: Mon, 05 Jan 2009 12:51:41 -0500
- Subject: C++ PATCH for c++/38701 and 38702
I had forgotten that DECL_ASSIGNMENT_OPERATOR_P includes things like +=...
Tested x86_64-pc-linux-gnu, applied to trunk.
2009-01-03 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.
* g++.dg/cpp0x/defaulted7.C: New test.
Index: cp/class.c
===================================================================
*** cp/class.c (revision 143045)
--- cp/class.c (working copy)
*************** defaultable_fn_p (tree fn)
*** 4147,4153 ****
}
else if (DECL_DESTRUCTOR_P (fn))
return true;
! else if (DECL_ASSIGNMENT_OPERATOR_P (fn))
return copy_fn_p (fn);
else
return false;
--- 4147,4154 ----
}
else if (DECL_DESTRUCTOR_P (fn))
return true;
! else if (DECL_ASSIGNMENT_OPERATOR_P (fn)
! && DECL_OVERLOADED_OPERATOR_P (fn) == NOP_EXPR)
return copy_fn_p (fn);
else
return false;
Index: cp/decl.c
===================================================================
*** cp/decl.c (revision 143045)
--- cp/decl.c (working copy)
*************** cp_finish_decl (tree decl, tree init, bo
*** 5517,5523 ****
else if (init == ridpointers[(int)RID_DEFAULT])
{
if (!defaultable_fn_p (decl))
! error ("%qD cannot be defaulted", decl);
else
DECL_DEFAULTED_FN (decl) = 1;
}
--- 5517,5526 ----
else if (init == ridpointers[(int)RID_DEFAULT])
{
if (!defaultable_fn_p (decl))
! {
! error ("%qD cannot be defaulted", decl);
! DECL_INITIAL (decl) = NULL_TREE;
! }
else
DECL_DEFAULTED_FN (decl) = 1;
}
Index: cp/cp-tree.h
===================================================================
*** cp/cp-tree.h (revision 143045)
--- cp/cp-tree.h (working copy)
*************** struct lang_decl GTY(())
*** 1878,1884 ****
(IDENTIFIER_OPNAME_P (DECL_NAME (NODE)) \
? DECL_LANG_SPECIFIC (NODE)->u.f.operator_code : ERROR_MARK)
! /* Nonzero if NODE is an assignment operator. */
#define DECL_ASSIGNMENT_OPERATOR_P(NODE) \
(DECL_LANG_SPECIFIC (NODE)->decl_flags.assignment_operator_p)
--- 1878,1884 ----
(IDENTIFIER_OPNAME_P (DECL_NAME (NODE)) \
? DECL_LANG_SPECIFIC (NODE)->u.f.operator_code : ERROR_MARK)
! /* Nonzero if NODE is an assignment operator (including += and such). */
#define DECL_ASSIGNMENT_OPERATOR_P(NODE) \
(DECL_LANG_SPECIFIC (NODE)->decl_flags.assignment_operator_p)
Index: testsuite/g++.dg/cpp0x/defaulted7.C
===================================================================
*** testsuite/g++.dg/cpp0x/defaulted7.C (revision 0)
--- testsuite/g++.dg/cpp0x/defaulted7.C (revision 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" }