This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

C++,v3 PATCH for c++/42983 (virtual vs. default)


The consensus on issue 906 in Santa Cruz was to require defaulted virtual functions to be defaulted outside the class so that it's clear they are user-provided. This required a few changes in the library; I dealt with it by just providing inline definitions after the class definition; do library folks want something else?

Tested x86_64-pc-linux-gnu, applied to trunk; the patch is local to C++0x mode.
commit 841e237bfb253dea368af671309c0010f45556b1
Author: Jason Merrill <jason@redhat.com>
Date:   Wed Feb 10 15:10:02 2010 -0500

    	PR c++/42983, core issue 906
    	* method.c (defaultable_fn_check): Check virtualness.
    	* include/std/thread (~_Impl_base): Move default out of line.
    	* libsupc++/nested_exception.h (~nested_exception): Likewise.

diff --git a/gcc/cp/method.c b/gcc/cp/method.c
index cda7ed3..ccc977d 100644
--- a/gcc/cp/method.c
+++ b/gcc/cp/method.c
@@ -1069,6 +1069,9 @@ defaultable_fn_check (tree fn)
 	  if (TYPE_RAISES_EXCEPTIONS (TREE_TYPE (fn)))
 	    error ("function %q+D defaulted on its first declaration "
 		   "must not have an exception-specification", fn);
+	  if (DECL_VIRTUAL_P (fn))
+	    error ("%qD declared virtual cannot be defaulted in the class "
+		   "body", fn);
 	}
       else if (!processing_template_decl)
 	defaulted_late_check (fn);
diff --git a/gcc/testsuite/g++.dg/cpp0x/defaulted15.C b/gcc/testsuite/g++.dg/cpp0x/defaulted15.C
index 092b560..b54cedb 100644
--- a/gcc/testsuite/g++.dg/cpp0x/defaulted15.C
+++ b/gcc/testsuite/g++.dg/cpp0x/defaulted15.C
@@ -41,3 +41,8 @@ struct G: public F
   // Can't be const because F copy ctor isn't.
   G(const G&) = default;	// { dg-error "const" }
 };
+
+struct H
+{
+  virtual ~H() = default;	// { dg-error "declared virtual" }
+};
diff --git a/gcc/testsuite/g++.dg/cpp0x/defaulted9.C b/gcc/testsuite/g++.dg/cpp0x/defaulted9.C
index f083479..1e5e2cb 100644
--- a/gcc/testsuite/g++.dg/cpp0x/defaulted9.C
+++ b/gcc/testsuite/g++.dg/cpp0x/defaulted9.C
@@ -4,9 +4,11 @@
 struct _Impl_base
 {
   _Impl_base() = default;
-  virtual ~_Impl_base() = default;
+  virtual ~_Impl_base();
 };
 
+inline _Impl_base::~_Impl_base() = default;
+
 template<typename _Tp>
 class _Impl : public _Impl_base
 { };
diff --git a/libstdc++-v3/include/std/thread b/libstdc++-v3/include/std/thread
index 2d7a751..628c34a 100644
--- a/libstdc++-v3/include/std/thread
+++ b/libstdc++-v3/include/std/thread
@@ -97,7 +97,7 @@ namespace std
     {
       __shared_base_type	_M_this_ptr;
 
-      virtual ~_Impl_base() = default;
+      virtual ~_Impl_base();
 
       virtual void _M_run() = 0;
     };
@@ -193,6 +193,8 @@ namespace std
       }
   };
 
+  inline thread::_Impl_base::~_Impl_base() = default;
+
   inline void
   swap(thread& __x, thread& __y)
   { __x.swap(__y); }
diff --git a/libstdc++-v3/libsupc++/nested_exception.h b/libstdc++-v3/libsupc++/nested_exception.h
index 9b05484..713c334 100644
--- a/libstdc++-v3/libsupc++/nested_exception.h
+++ b/libstdc++-v3/libsupc++/nested_exception.h
@@ -63,7 +63,7 @@ namespace std
 
     nested_exception& operator=(const nested_exception&) = default;
 
-    virtual ~nested_exception() = default;
+    virtual ~nested_exception();
 
     void
     rethrow_nested() const __attribute__ ((__noreturn__))
@@ -74,6 +74,8 @@ namespace std
     { return _M_ptr; }
   };
 
+  inline nested_exception::~nested_exception() = default;
+
   template<typename _Except>
     struct _Nested_exception : public _Except, public nested_exception
     {
diff --git a/libstdc++-v3/testsuite/18_support/nested_exception/rethrow_if_nested.cc b/libstdc++-v3/testsuite/18_support/nested_exception/rethrow_if_nested.cc
index 37d1d80..ec8d172 100644
--- a/libstdc++-v3/testsuite/18_support/nested_exception/rethrow_if_nested.cc
+++ b/libstdc++-v3/testsuite/18_support/nested_exception/rethrow_if_nested.cc
@@ -23,7 +23,8 @@
 
 struct derived : std::nested_exception { };
 
-struct base { virtual ~base() = default; };
+struct base { virtual ~base(); };
+inline base::~base() = default;
 
 struct derived2 : base, std::nested_exception { };
 
diff --git a/libstdc++-v3/testsuite/18_support/nested_exception/throw_with_nested.cc b/libstdc++-v3/testsuite/18_support/nested_exception/throw_with_nested.cc
index 9ce31f0..c846d09 100644
--- a/libstdc++-v3/testsuite/18_support/nested_exception/throw_with_nested.cc
+++ b/libstdc++-v3/testsuite/18_support/nested_exception/throw_with_nested.cc
@@ -23,7 +23,8 @@
 
 struct derived : std::nested_exception { };
 
-struct not_derived { virtual ~not_derived() = default; };
+struct not_derived { virtual ~not_derived(); };
+inline not_derived::~not_derived() = default;
 
 void test01() 
 {

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]