PR c++/46807
authorjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 16 Feb 2011 00:39:27 +0000 (00:39 +0000)
committerjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 16 Feb 2011 00:39:27 +0000 (00:39 +0000)
* method.c (synthesized_method_walk): Always exit early for
trivial fn in C++98 mode.

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

gcc/cp/ChangeLog
gcc/cp/method.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/implicit-trivial1.C [new file with mode: 0644]
gcc/testsuite/g++.dg/inherit/implicit-trivial1.C [new file with mode: 0644]

index 61a3e4a..0fdac3c 100644 (file)
@@ -1,3 +1,9 @@
+2011-02-15  Jason Merrill  <jason@redhat.com>
+
+       PR c++/46807
+       * method.c (synthesized_method_walk): Always exit early for
+       trivial fn in C++98 mode.
+
 2011-02-14  Jason Merrill  <jason@redhat.com>
 
        PR c++/47482
index 3f0baed..bfe8a06 100644 (file)
@@ -1153,13 +1153,15 @@ synthesized_method_walk (tree ctype, special_function_kind sfk, bool const_p,
   if (trivial_p)
     *trivial_p = expected_trivial;
 
-#ifndef ENABLE_CHECKING
   /* The TYPE_HAS_COMPLEX_* flags tell us about constraints from base
      class versions and other properties of the type.  But a subobject
      class can be trivially copyable and yet have overload resolution
      choose a template constructor for initialization, depending on
      rvalueness and cv-quals.  So we can't exit early for copy/move
-     methods in C++0x.  */
+     methods in C++0x.  The same considerations apply in C++98/03, but
+     there the definition of triviality does not consider overload
+     resolution, so a constructor can be trivial even if it would otherwise
+     call a non-trivial constructor.  */
   if (expected_trivial
       && (!copy_arg_p || cxx_dialect < cxx0x))
     {
@@ -1167,7 +1169,6 @@ synthesized_method_walk (tree ctype, special_function_kind sfk, bool const_p,
        *constexpr_p = synthesized_default_constructor_is_constexpr (ctype);
       return;
     }
-#endif
 
   ++cp_unevaluated_operand;
   ++c_inhibit_evaluation_warnings;
@@ -1300,14 +1301,6 @@ synthesized_method_walk (tree ctype, special_function_kind sfk, bool const_p,
       if (spec_p)
        *spec_p = merge_exception_specifiers (*spec_p, cleanup_spec);
     }
-
-#ifdef ENABLE_CHECKING
-  /* If we expected this to be trivial but it isn't, then either we're in
-     C++0x mode and this is a copy/move ctor/op= or there's an error.  */
-  gcc_assert (!(trivial_p && expected_trivial && !*trivial_p)
-             || (copy_arg_p && cxx_dialect >= cxx0x)
-             || errorcount);
-#endif
 }
 
 /* DECL is a deleted function.  If it's implicitly deleted, explain why and
index d6834fb..2608ce5 100644 (file)
@@ -1,3 +1,8 @@
+2011-02-15  Jason Merrill  <jason@redhat.com>
+
+       * g++.dg/inherit/implicit-trivial1.C: New.
+       * g++.dg/cpp0x/implicit-trivial1.C: New.
+
 2011-02-15  H.J. Lu  <hongjiu.lu@intel.com>
 
        PR middle-end/47725
diff --git a/gcc/testsuite/g++.dg/cpp0x/implicit-trivial1.C b/gcc/testsuite/g++.dg/cpp0x/implicit-trivial1.C
new file mode 100644 (file)
index 0000000..64084c1
--- /dev/null
@@ -0,0 +1,23 @@
+// PR c++/46807
+// { dg-options -std=c++0x }
+// In C++98/03, B::B(const B&) is trivial because A::A(const A&) is trivial,
+// even though doing overload resolution would mean calling the template
+// constructor.  In C++0x, we do overload resolution to determine triviality.
+
+struct A
+{
+  A() {}
+private:
+  template <class T> A(T&);    // { dg-error "private" }
+};
+
+struct B                       // { dg-error "implicitly deleted|this context" }
+{
+  mutable A a;
+};
+
+int main()
+{
+  B b;
+  B b2(b);                     // { dg-error "deleted" }
+}
diff --git a/gcc/testsuite/g++.dg/inherit/implicit-trivial1.C b/gcc/testsuite/g++.dg/inherit/implicit-trivial1.C
new file mode 100644 (file)
index 0000000..e63bd34
--- /dev/null
@@ -0,0 +1,23 @@
+// PR c++/46807
+// { dg-options -std=c++98 }
+// In C++98/03, B::B(const B&) is trivial because A::A(const A&) is trivial,
+// even though doing overload resolution would mean calling the template
+// constructor.  In C++0x, we do overload resolution to determine triviality.
+
+struct A
+{
+  A() {}
+private:
+  template <class T> A(T&);
+};
+
+struct B
+{
+  mutable A a;
+};
+
+int main()
+{
+  B b;
+  B b2(b);
+}