This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
C++ PATCH for c++/44366 (segv with decltype)
- From: Jason Merrill <jason at redhat dot com>
- To: gcc-patches List <gcc-patches at gcc dot gnu dot org>
- Date: Tue, 08 Jun 2010 00:33:34 -0400
- Subject: C++ PATCH for c++/44366 (segv with decltype)
We were getting an infinite recursion trying to print the error context
for a member function of a local class because we ended up trying to
print the DECL_CONTEXT of a PARM_DECL used in the type of another parm.
Tested x86_64-pc-linux-gnu, applied to trunk. dump_simple_decl hunk
also applied to 4.5.
commit d78ac3dbb50e9a3cf287f5bf2b5d535cdcbd41bc
Author: Jason Merrill <jason@redhat.com>
Date: Mon Jun 7 20:03:36 2010 -0400
PR c++/44366
* error.c (dump_parameters): Mask out TFF_SCOPE.
(dump_simple_decl): Don't print the scope of a PARM_DECL.
(dump_scope): Remove no-op mask.
diff --git a/gcc/cp/error.c b/gcc/cp/error.c
index d535f05..7730e4b 100644
--- a/gcc/cp/error.c
+++ b/gcc/cp/error.c
@@ -115,7 +115,7 @@ init_error (void)
static void
dump_scope (tree scope, int flags)
{
- int f = ~TFF_RETURN_TYPE & (flags & (TFF_SCOPE | TFF_CHASE_TYPEDEF));
+ int f = flags & (TFF_SCOPE | TFF_CHASE_TYPEDEF);
if (scope == NULL_TREE)
return;
@@ -865,6 +865,7 @@ dump_simple_decl (tree t, tree type, int flags)
pp_maybe_space (cxx_pp);
}
if (! (flags & TFF_UNQUALIFIED_NAME)
+ && TREE_CODE (t) != PARM_DECL
&& (!DECL_INITIAL (t)
|| TREE_CODE (DECL_INITIAL (t)) != TEMPLATE_PARM_INDEX))
dump_scope (CP_DECL_CONTEXT (t), flags);
@@ -1355,6 +1356,7 @@ static void
dump_parameters (tree parmtypes, int flags)
{
int first = 1;
+ flags &= ~TFF_SCOPE;
pp_cxx_left_paren (cxx_pp);
for (first = 1; parmtypes != void_list_node;
diff --git a/gcc/testsuite/g++.dg/cpp0x/decltype23.C b/gcc/testsuite/g++.dg/cpp0x/decltype23.C
new file mode 100644
index 0000000..6d8dff9
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/decltype23.C
@@ -0,0 +1,12 @@
+// PR c++/44366
+// While printing the operand of decltype We were trying to print f as the
+// scope of t, causing infinite recursion.
+// { dg-options "-std=c++0x" }
+
+template <typename T>
+void f(T t, decltype(*t))
+{
+ struct A { void g() {
+ foo; // { dg-error "foo" }
+ } };
+}