* class.c (type_has_virtual_destructor): New.
authorjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 30 Jun 2010 00:50:45 +0000 (00:50 +0000)
committerjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 30 Jun 2010 00:50:45 +0000 (00:50 +0000)
* cp-tree.h: Declare it.
* semantics.c (trait_expr_value): Use it.

* call.c (build_over_call): Only give warnings with tf_warning.

* name-lookup.c (pop_scope): Handle NULL_TREE.

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

12 files changed:
gcc/cp/ChangeLog
gcc/cp/call.c
gcc/cp/class.c
gcc/cp/cp-tree.h
gcc/cp/decl.c
gcc/cp/name-lookup.c
gcc/cp/semantics.c
gcc/cp/tree.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/defaulted19.C [new file with mode: 0644]
gcc/testsuite/g++.dg/expr/string-1.C
gcc/testsuite/g++.dg/template/error23.C

index 7eaca7f..bc02bd0 100644 (file)
@@ -1,5 +1,13 @@
 2010-06-29  Jason Merrill  <jason@redhat.com>
 
+       * class.c (type_has_virtual_destructor): New.
+       * cp-tree.h: Declare it.
+       * semantics.c (trait_expr_value): Use it.
+
+       * call.c (build_over_call): Only give warnings with tf_warning.
+
+       * name-lookup.c (pop_scope): Handle NULL_TREE.
+
        * cp-tree.h (TYPE_HAS_ASSIGN_REF): Rename to TYPE_HAS_COPY_ASSIGN.
        (TYPE_HAS_CONST_ASSIGN_REF): Rename to TYPE_HAS_CONST_COPY_ASSIGN.
        (TYPE_HAS_INIT_REF): Rename to TYPE_HAS_COPY_CTOR.
index c05e5a1..852c7ea 100644 (file)
@@ -5600,7 +5600,7 @@ build_over_call (struct z_candidate *cand, int flags, tsubst_flags_t complain)
     }
 
   /* Give any warnings we noticed during overload resolution.  */
-  if (cand->warnings)
+  if (cand->warnings && (complain & tf_warning))
     {
       struct candidate_warning *w;
       for (w = cand->warnings; w; w = w->next)
index 3a87555..bfd3113 100644 (file)
@@ -3838,7 +3838,9 @@ check_methods (tree t)
          if (DECL_PURE_VIRTUAL_P (x))
            VEC_safe_push (tree, gc, CLASSTYPE_PURE_VIRTUALS (t), x);
        }
-      /* All user-provided destructors are non-trivial.  */
+      /* All user-provided destructors are non-trivial.
+         Constructors and assignment ops are handled in
+        grok_special_member_properties.  */
       if (DECL_DESTRUCTOR_P (x) && user_provided_p (x))
        TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t) = 1;
     }
@@ -4260,6 +4262,21 @@ type_has_user_provided_default_constructor (tree t)
   return false;
 }
 
+/* Returns true iff class TYPE has a virtual destructor.  */
+
+bool
+type_has_virtual_destructor (tree type)
+{
+  tree dtor;
+
+  if (!CLASS_TYPE_P (type))
+    return false;
+
+  gcc_assert (COMPLETE_TYPE_P (type));
+  dtor = CLASSTYPE_DESTRUCTORS (type);
+  return (dtor && DECL_VIRTUAL_P (dtor));
+}
+
 /* Remove all zero-width bit-fields from T.  */
 
 static void
index 1b3c2f0..bfdf036 100644 (file)
@@ -4655,6 +4655,7 @@ extern tree in_class_defaulted_default_constructor (tree);
 extern bool user_provided_p                    (tree);
 extern bool type_has_user_provided_constructor  (tree);
 extern bool type_has_user_provided_default_constructor (tree);
+extern bool type_has_virtual_destructor                (tree);
 extern void defaulted_late_check               (tree);
 extern bool defaultable_fn_check               (tree);
 extern void fixup_type_variants                        (tree);
@@ -5280,6 +5281,7 @@ extern bool pod_type_p                            (const_tree);
 extern bool layout_pod_type_p                  (const_tree);
 extern bool std_layout_type_p                  (const_tree);
 extern bool trivial_type_p                     (const_tree);
+extern bool trivially_copyable_p               (const_tree);
 extern bool type_has_nontrivial_default_init   (const_tree);
 extern bool type_has_nontrivial_copy_init      (const_tree);
 extern bool class_tmpl_impl_spec_p             (const_tree);
index 1011243..0c2f7e5 100644 (file)
@@ -10295,6 +10295,7 @@ grok_special_member_properties (tree decl)
            TYPE_HAS_CONST_COPY_ASSIGN (class_type) = 1;
        }
     }
+  /* Destructors are handled in check_methods.  */
 }
 
 /* Check a constructor DECL has the correct form.  Complains
index 4e40e3b..6713119 100644 (file)
@@ -2480,6 +2480,8 @@ push_scope (tree t)
 void
 pop_scope (tree t)
 {
+  if (t == NULL_TREE)
+    return;
   if (TREE_CODE (t) == NAMESPACE_DECL)
     pop_decl_namespace ();
   else if CLASS_TYPE_P (t)
index 9dae90b..adc5e7f 100644 (file)
@@ -5104,8 +5104,7 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2)
                  && TYPE_HAS_TRIVIAL_DESTRUCTOR (type1)));
 
     case CPTK_HAS_VIRTUAL_DESTRUCTOR:
-      return (CLASS_TYPE_P (type1)
-             && (t = locate_dtor (type1, NULL)) && DECL_VIRTUAL_P (t));
+      return type_has_virtual_destructor (type1);
 
     case CPTK_IS_ABSTRACT:
       return (CLASS_TYPE_P (type1) && CLASSTYPE_PURE_VIRTUALS (type1));
index f7ce655..7236924 100644 (file)
@@ -2381,22 +2381,37 @@ type_has_nontrivial_copy_init (const_tree t)
     return 0;
 }
 
-/* Returns 1 iff type T is a trivial type, as defined in [basic.types].  */
+/* Returns 1 iff type T is a trivially copyable type, as defined in
+   [basic.types] and [class].  */
 
 bool
-trivial_type_p (const_tree t)
+trivially_copyable_p (const_tree t)
 {
   t = strip_array_types (CONST_CAST_TREE (t));
 
   if (CLASS_TYPE_P (t))
-    return (TYPE_HAS_TRIVIAL_DFLT (t)
-           && TYPE_HAS_TRIVIAL_COPY_CTOR (t)
+    return (TYPE_HAS_TRIVIAL_COPY_CTOR (t)
            && TYPE_HAS_TRIVIAL_COPY_ASSIGN (t)
            && TYPE_HAS_TRIVIAL_DESTRUCTOR (t));
   else
     return scalarish_type_p (t);
 }
 
+/* Returns 1 iff type T is a trivial type, as defined in [basic.types] and
+   [class].  */
+
+bool
+trivial_type_p (const_tree t)
+{
+  t = strip_array_types (CONST_CAST_TREE (t));
+
+  if (CLASS_TYPE_P (t))
+    return (TYPE_HAS_TRIVIAL_DFLT (t)
+           && trivially_copyable_p (t));
+  else
+    return scalarish_type_p (t);
+}
+
 /* Returns 1 iff type T is a POD type, as defined in [basic.types].  */
 
 bool
index 4e37174..2d1aa2d 100644 (file)
@@ -1,3 +1,10 @@
+2010-06-29  Jason Merrill  <jason@redhat.com>
+
+       * g++.dg/cpp0x/defaulted19.C: New.
+
+       * g++.dg/expr/string-1.C: Fix for -std=c++0x.
+       * g++.dg/template/error23.C: Fix for -std=c++0x.
+
 2010-06-29  Janus Weil  <janus@gcc.gnu.org>
 
        PR fortran/44718
diff --git a/gcc/testsuite/g++.dg/cpp0x/defaulted19.C b/gcc/testsuite/g++.dg/cpp0x/defaulted19.C
new file mode 100644 (file)
index 0000000..ea33df3
--- /dev/null
@@ -0,0 +1,21 @@
+// We allocate a cookie to help us run the destructor even if it's deleted.
+// { dg-options -std=c++0x }
+// { dg-do run }
+
+struct A
+{
+  ~A() = delete;
+};
+
+void *p = 0;
+void *operator new[](__SIZE_TYPE__ t)
+{
+  p = ::operator new (t);
+  return p;
+}
+
+int main()
+{
+  A* ap = new A[5];
+  return ap == p;
+}
index 3901427..9a0a5ff 100644 (file)
@@ -1,9 +1,11 @@
 // { dg-do compile }
 // This testcase used to seg fault (PR c++/38648)
 
+// { dg-prune-output "initializer lists" }
+
 char a[1];
 
-int foo( // { dg-error "extended initializer lists only available" }
+int foo(
 {
   a = ""; // { dg-error "" }
   return 0; // { dg-error "" }
index 8e5dee7..f21d8d9 100644 (file)
@@ -8,10 +8,10 @@ struct nullptr_type {
   operator T* ( void ) const {
     return ( 0 );
   }
-} const nullptr;
+} const nullptr_ob;
 
 int main ( void ) {
-  0 == nullptr; // { dg-error "match" }
+  0 == nullptr_ob; // { dg-error "match" }
 }