diff mbox

C++ PATCH for c++/50531 (ICE with template dtor defaulted outside fn)

Message ID 4E9DCE9D.1060504@redhat.com
State New
Headers show

Commit Message

Jason Merrill Oct. 18, 2011, 7:08 p.m. UTC
Here we were failing to recognize that a defaulted fn had already been 
instantiated, and crashed trying to instantiate it again.

Tested x86_64-pc-linux-gnu, applying to trunk and 4.6.
diff mbox

Patch

commit 10ff48cb9f7817ae8e95e71bd4b22989dafb2be2
Author: Jason Merrill <jason@redhat.com>
Date:   Tue Oct 18 14:25:42 2011 -0400

    	PR c++/50531
    	* pt.c (instantiate_decl): Recognize when a function defaulted
    	outside the class is already instantiated.

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 6fc60d5..56fa632 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -18045,6 +18045,8 @@  instantiate_decl (tree d, int defer_ok,
     d = DECL_CLONED_FUNCTION (d);
 
   if (DECL_TEMPLATE_INSTANTIATED (d)
+      || (TREE_CODE (d) == FUNCTION_DECL
+	  && DECL_DEFAULTED_FN (d) && DECL_INITIAL (d))
       || DECL_TEMPLATE_SPECIALIZATION (d))
     /* D has already been instantiated or explicitly specialized, so
        there's nothing for us to do here.
diff --git a/gcc/testsuite/g++.dg/cpp0x/defaulted32.C b/gcc/testsuite/g++.dg/cpp0x/defaulted32.C
new file mode 100644
index 0000000..351cdae
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/defaulted32.C
@@ -0,0 +1,21 @@ 
+// PR c++/50531
+// { dg-options -std=c++0x }
+
+template <typename T>
+class DataFilter
+{
+ public:
+  inline virtual ~DataFilter();
+};
+
+template<typename T>
+inline DataFilter<T>::~DataFilter() = default;
+
+class ARCalculator : public DataFilter<ARCalculator>
+{
+ public:
+  virtual void dataStart(int, int);
+};
+
+void ARCalculator::dataStart(int, int)
+{}