* C++ PATCH for c++/61566 (ICE with lambda in template default arg)
@ 2014-06-30 18:50 Jason Merrill
2014-08-15 22:27 ` Jason Merrill
0 siblings, 1 reply; 2+ messages in thread
From: Jason Merrill @ 2014-06-30 18:50 UTC (permalink / raw)
To: gcc-patches List
[-- Attachment #1: Type: text/plain, Size: 146 bytes --]
decl_mangling_context was failing to recognize a lambda in template
context as a lambda.
Tested x86_64-pc-linux-gnu, applying to 4.9 and trunk.
[-- Attachment #2: 61566.patch --]
[-- Type: text/x-patch, Size: 1179 bytes --]
commit 1ba7cf95c0b024c7a3372e0734d7bf620f31dd14
Author: Jason Merrill <jason@redhat.com>
Date: Mon Jun 30 12:08:09 2014 -0400
PR c++/61566
* mangle.c (decl_mangling_context): Look through a TEMPLATE_DECL.
diff --git a/gcc/cp/mangle.c b/gcc/cp/mangle.c
index ac1c1da..02c05d4 100644
--- a/gcc/cp/mangle.c
+++ b/gcc/cp/mangle.c
@@ -742,6 +742,10 @@ decl_mangling_context (tree decl)
if (tcontext != NULL_TREE)
return tcontext;
+ if (TREE_CODE (decl) == TEMPLATE_DECL
+ && DECL_TEMPLATE_RESULT (decl))
+ decl = DECL_TEMPLATE_RESULT (decl);
+
if (TREE_CODE (decl) == TYPE_DECL
&& LAMBDA_TYPE_P (TREE_TYPE (decl)))
{
diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-template13.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-template13.C
new file mode 100644
index 0000000..adbb4db
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-template13.C
@@ -0,0 +1,20 @@
+// PR c++/61566
+// { dg-do compile { target c++11 } }
+
+struct function
+{
+ template < typename _Functor>
+ function (_Functor);
+};
+
+struct C
+{
+ template <typename T>
+ void foo (T, function = [] {});
+};
+
+void bar ()
+{
+ C c;
+ c.foo (1);
+}
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: C++ PATCH for c++/61566 (ICE with lambda in template default arg)
2014-06-30 18:50 C++ PATCH for c++/61566 (ICE with lambda in template default arg) Jason Merrill
@ 2014-08-15 22:27 ` Jason Merrill
0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2014-08-15 22:27 UTC (permalink / raw)
To: gcc-patches List
[-- Attachment #1: Type: text/plain, Size: 274 bytes --]
On 06/30/2014 02:49 PM, Jason Merrill wrote:
> decl_mangling_context was failing to recognize a lambda in template
> context as a lambda.
It turns out that was far from the only issue with a lambda in a member
template....
Tested x86_64-pc-linux-gnu, applying to trunk.
[-- Attachment #2: 61566-2.patch --]
[-- Type: text/x-patch, Size: 2938 bytes --]
commit 55ef57277be5885a78bacf4e979a8def08e4fbb6
Author: Jason Merrill <jason@redhat.com>
Date: Fri Aug 15 01:53:54 2014 -0400
PR c++/61566
* pt.c (instantiate_class_template_1): Ignore lambda on
CLASSTYPE_DECL_LIST.
(push_template_decl_real): A lambda is not primary.
* lambda.c (maybe_add_lambda_conv_op): Distinguish between being
currently in a function and the lambda living in a function.
diff --git a/gcc/cp/lambda.c b/gcc/cp/lambda.c
index 169f438..ddaa940 100644
--- a/gcc/cp/lambda.c
+++ b/gcc/cp/lambda.c
@@ -824,6 +824,7 @@ void
maybe_add_lambda_conv_op (tree type)
{
bool nested = (current_function_decl != NULL_TREE);
+ bool nested_def = decl_function_context (TYPE_MAIN_DECL (type));
tree callop = lambda_function (type);
if (LAMBDA_EXPR_CAPTURE_LIST (CLASSTYPE_LAMBDA_EXPR (type)) != NULL_TREE)
@@ -976,7 +977,7 @@ maybe_add_lambda_conv_op (tree type)
DECL_NOT_REALLY_EXTERN (fn) = 1;
DECL_DECLARED_INLINE_P (fn) = 1;
DECL_ARGUMENTS (fn) = build_this_parm (fntype, TYPE_QUAL_CONST);
- if (nested)
+ if (nested_def)
DECL_INTERFACE_KNOWN (fn) = 1;
if (generic_lambda_p)
@@ -1016,7 +1017,7 @@ maybe_add_lambda_conv_op (tree type)
DECL_NAME (arg) = NULL_TREE;
DECL_CONTEXT (arg) = fn;
}
- if (nested)
+ if (nested_def)
DECL_INTERFACE_KNOWN (fn) = 1;
if (generic_lambda_p)
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 6a7bcb8..611bfd6 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -4722,6 +4722,9 @@ push_template_decl_real (tree decl, bool is_friend)
template <typename T> friend void A<T>::f();
is not primary. */
is_primary = false;
+ else if (TREE_CODE (decl) == TYPE_DECL
+ && LAMBDA_TYPE_P (TREE_TYPE (decl)))
+ is_primary = false;
else
is_primary = template_parm_scope_p ();
@@ -9237,6 +9242,11 @@ instantiate_class_template_1 (tree type)
&& DECL_OMP_DECLARE_REDUCTION_P (r))
cp_check_omp_declare_reduction (r);
}
+ else if (DECL_CLASS_TEMPLATE_P (t)
+ && LAMBDA_TYPE_P (TREE_TYPE (t)))
+ /* A closure type for a lambda in a default argument for a
+ member template. Ignore it; it will be instantiated with
+ the default argument. */;
else
{
/* Build new TYPE_FIELDS. */
diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-template13.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-template13.C
index adbb4db..2b1a605 100644
--- a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-template13.C
+++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-template13.C
@@ -7,6 +7,7 @@ struct function
function (_Functor);
};
+template <class U>
struct C
{
template <typename T>
@@ -15,6 +16,9 @@ struct C
void bar ()
{
- C c;
+ C<int> c;
c.foo (1);
}
+
+// { dg-final { scan-assembler "_ZN8functionC1IZN1CIiE3fooIiEEvT_S_Ed_UlvE_EET_" } }
+// { dg-final { scan-assembler-not "_ZZN1CIiE3fooIiEEvT_8functionEd_NKUlvE_clEv" } }
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2014-08-15 22:27 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-06-30 18:50 C++ PATCH for c++/61566 (ICE with lambda in template default arg) Jason Merrill
2014-08-15 22:27 ` 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).