diff mbox

Some small C++ PATCHes

Message ID 4DAFB21E.8070004@redhat.com
State New
Headers show

Commit Message

Jason Merrill April 21, 2011, 4:27 a.m. UTC
1) While looking at 48530 I noticed that my recent change to put array 
literals in static storage again needed to check for non-trivial 
destructors.

2) I also added support for trivial destructors to build_over_call, 
though it isn't currently used by anything.

3) lookup_fnfields_slot wasn't causing the type to be completed, which 
isn't currently an issue on the trunk, but was when backporting to 4.4.

Tested x86_64-pc-linux-gnu, applied to trunk.  Patch 1 also applied to 4.6.
commit cc1fefa687f03b99b3ac88782d2264561f603401
Author: Jason Merrill <jason@redhat.com>
Date:   Wed Apr 20 13:05:15 2011 -0700

    	* semantics.c (finish_compound_literal): Don't put an array
    	with a dtor in a static variable.
commit 3bde00a1e03ff09f14bd70454d1b4ceb5047b8b3
Author: Jason Merrill <jason@redhat.com>
Date:   Wed Apr 20 13:04:50 2011 -0700

    	* call.c (build_over_call): Handle trivial dtor.

diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index 78104b1..cf8e1a5 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -6411,7 +6411,11 @@ build_over_call (struct z_candidate *cand, int flags, tsubst_flags_t complain)
 
       return val;
     }
-  /* FIXME handle trivial default constructor and destructor, too.  */
+  else if (DECL_DESTRUCTOR_P (fn)
+	   && trivial_fn_p (fn)
+	   && !DECL_DELETED_FN (fn))
+    return fold_convert (void_type_node, argarray[0]);
+  /* FIXME handle trivial default constructor, too.  */
 
   if (!already_used)
     mark_used (fn);
diff --git a/gcc/testsuite/g++.dg/init/dtor4.C b/gcc/testsuite/g++.dg/init/dtor4.C
new file mode 100644
index 0000000..4bca69e
--- /dev/null
+++ b/gcc/testsuite/g++.dg/init/dtor4.C
@@ -0,0 +1,9 @@
+// { dg-final { scan-assembler-not "_ZN1AD2Ev" } }
+
+struct A { };
+
+int main()
+{
+  A a;
+  a.~A();
+}
commit a2ff11d1ecbd5f238080fd6e3f95fa13d3cefff2
Author: Jason Merrill <jason@redhat.com>
Date:   Wed Apr 20 15:59:38 2011 -0700

    	* search.c (lookup_fnfields_slot): Call complete_type.

diff --git a/gcc/cp/search.c b/gcc/cp/search.c
index 9ec6fc3..e7d2048 100644
--- a/gcc/cp/search.c
+++ b/gcc/cp/search.c
@@ -1451,7 +1451,7 @@ lookup_fnfields_1 (tree type, tree name)
 tree
 lookup_fnfields_slot (tree type, tree name)
 {
-  int ix = lookup_fnfields_1 (type, name);
+  int ix = lookup_fnfields_1 (complete_type (type), name);
   if (ix < 0)
     return NULL_TREE;
   return VEC_index (tree, CLASSTYPE_METHOD_VEC (type), ix);
diff mbox

Patch

diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index e9b1907..7763ae0 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -2383,6 +2383,7 @@  finish_compound_literal (tree type, tree compound_literal,
      represent class temporaries with TARGET_EXPR so we elide copies.  */
   if ((!at_function_scope_p () || CP_TYPE_CONST_P (type))
       && TREE_CODE (type) == ARRAY_TYPE
+      && !TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type)
       && initializer_constant_valid_p (compound_literal, type))
     {
       tree decl = create_temporary_var (type);
diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist47.C b/gcc/testsuite/g++.dg/cpp0x/initlist47.C
new file mode 100644
index 0000000..b76fb58
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/initlist47.C
@@ -0,0 +1,9 @@ 
+// { dg-options -std=c++0x }
+
+struct A { ~A() = delete; };	// { dg-error "declared" }
+
+int main()
+{
+  typedef const A cA[2];
+  cA{};				// { dg-error "deleted" }
+}