* C++ PATCH for c++/47687 (infinite recursion with lambda returning lambda)
@ 2011-05-27 22:44 Jason Merrill
0 siblings, 0 replies; only message in thread
From: Jason Merrill @ 2011-05-27 22:44 UTC (permalink / raw)
To: gcc-patches List
[-- Attachment #1: Type: text/plain, Size: 375 bytes --]
Here, deciding whether the nested lambda was dependent meant checking
the enclosing function, which meant checking the function's type, which
meant checking its return type, the nested lambda. I've broken this
cycle by looking not at whether the enclosing function is a dependent
expression, but whether it is a template.
Tested x86_64-pc-linux-gnu, applying to trunk.
[-- Attachment #2: 47687.patch --]
[-- Type: text/x-patch, Size: 1480 bytes --]
commit 5656f70c3b34354e29de75db6dad0a0b44ef6f04
Author: Jason Merrill <jason@redhat.com>
Date: Fri May 27 12:05:59 2011 -0400
PR c++/47687
* pt.c (dependent_type_p_r): Avoid infinite recursion.
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 71fe0a0..ae3d83d 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -18260,8 +18260,15 @@ dependent_type_p_r (tree type)
scope = TYPE_CONTEXT (type);
if (scope && TYPE_P (scope))
return dependent_type_p (scope);
- else if (scope && TREE_CODE (scope) == FUNCTION_DECL)
- return type_dependent_expression_p (scope);
+ /* Don't use type_dependent_expression_p here, as it can lead
+ to infinite recursion trying to determine whether a lambda
+ nested in a lambda is dependent (c++/47687). */
+ else if (scope && TREE_CODE (scope) == FUNCTION_DECL
+ && DECL_LANG_SPECIFIC (scope)
+ && DECL_TEMPLATE_INFO (scope)
+ && (any_dependent_template_arguments_p
+ (INNERMOST_TEMPLATE_ARGS (DECL_TI_ARGS (scope)))))
+ return true;
/* Other types are non-dependent. */
return false;
diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-nested4.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-nested4.C
new file mode 100644
index 0000000..a5bd1a2
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-nested4.C
@@ -0,0 +1,9 @@
+// PR c++/47687
+// { dg-options -std=c++0x }
+
+template <class T> struct A { };
+
+auto inl = []{ return []{}; }();
+typedef decltype(inl) inlt;
+
+A<inlt> a;
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2011-05-27 19:25 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-05-27 22:44 C++ PATCH for c++/47687 (infinite recursion with lambda returning lambda) Jason Merrill
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).