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]

Re: PR c++/42758


On Mon, Jan 18, 2010 at 05:05:57PM -0500, Jason Merrill wrote:
> Returning the template itself seems wrong to me; if we don't want to
> do what the caller is asking for, we should return error_mark_node.

OK. Hopefully the patch below does that.
Tested on x86_64-unknown-linux-gnu against trunk.

Thanks.

        Dodji

commit 892ea2eaca7a5f5eaef881afbaabea4f14a7e416
Author: Dodji Seketeli <dodji@redhat.com>
Date:   Mon Jan 18 20:25:31 2010 +0100

    Fix PR c++/42758
    
    gcc/cp/ChangeLog:
    	PR c++/42758
    	* pt.c (tsubst_aggr_type): Don't create a new class type when
    	tf_no_class_instantiations is set.
    
    gcc/testsuite/ChangeLog:
    	PR c++/42758
    	* g++.dg/other/crash-5.C: New test.

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index f27b931..c9927a3 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -8512,6 +8512,12 @@ tsubst_aggr_type (tree t,
 	  int saved_unevaluated_operand;
 	  int saved_inhibit_evaluation_warnings;
 
+	  /* The call to lookup_template_class below is likely to create
+	     a new class type, but we shouldn't create new class types if
+	     we were instructed to avoid class instantiations.  */
+	  if (complain & tf_no_class_instantiations)
+	    return error_mark_node;
+
 	  /* In "sizeof(X<I>)" we need to evaluate "I".  */
 	  saved_unevaluated_operand = cp_unevaluated_operand;
 	  cp_unevaluated_operand = 0;
diff --git a/gcc/testsuite/g++.dg/other/crash-5.C b/gcc/testsuite/g++.dg/other/crash-5.C
new file mode 100644
index 0000000..4205a33
--- /dev/null
+++ b/gcc/testsuite/g++.dg/other/crash-5.C
@@ -0,0 +1,19 @@
+// Origin: PR c++/42758
+// { dg-do compile }
+
+#include <cassert>
+#include <set>
+
+namespace spot
+{
+  struct int_less_than
+  {
+    bool operator()(int, int) const { return 0; }
+  };
+
+  int f(const std::set<int, int_less_than>&)
+  {
+    ((0) ? static_cast<void> (0) : __assert_fail ("0", "bug.cc", 13, __PRETTY_FUNCTION__));
+    return 1;
+  }
+}


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