diff options
author | Patrick Palka <ppalka@redhat.com> | 2020-04-13 16:53:41 -0400 |
---|---|---|
committer | Patrick Palka <ppalka@redhat.com> | 2020-04-13 16:53:48 -0400 |
commit | 1dcb779916502a44b4ae67d6bf60eb59474bd78c (patch) | |
tree | f8499f13cfb96cc5bbd20c877718db221455f658 /gcc | |
parent | 077dd9b3f17710da8af6adce816754ddceb57b5a (diff) | |
download | gcc-1dcb779916502a44b4ae67d6bf60eb59474bd78c.zip gcc-1dcb779916502a44b4ae67d6bf60eb59474bd78c.tar.gz gcc-1dcb779916502a44b4ae67d6bf60eb59474bd78c.tar.bz2 |
c++: Infinite diagnostic loop with decltype([]{}) [PR94521]
We are hitting a recursive loop when printing the signature of a function
containing a decltype([]{}) type. The loop is
dump_function_decl -> dump_substitution
-> dump_template_bindings
-> dump_type
-> dump_aggr_type
-> dump_scope -> dump_function_decl
and we loop because dump_template_bindings wants to print the resolved type of
decltype([]{}) (i.e. just a lambda type), so it calls dump_aggr_type, which
wants to print the function scope of the lambda type. But the function scope of
the lambda type is the function which we're in the middle of printing.
This patch breaks the loop by passing TFF_NO_FUNCTION_ARGUMENTS to
dump_function_decl from dump_scope, so that we avoid recursing into
dump_substitution and ultimately looping.
This also means we no longer emit the "[with ...]" clause when printing a
function template scope, and we instead just emit its template argument list in
a more natural way, e.g. instead of
foo(int, char) [with T=bool]::x
we would now print
foo<bool>::x
which seems like an improvement on its own.
The full signature of the function 'spam' in the below testcase is now
void spam(decltype (<lambda>)*) [with T = int; decltype (<lambda>) = spam<int>::<lambda()>]
gcc/cp/ChangeLog:
PR c++/94521
* error.c (dump_scope): Pass TFF_NO_FUNCTION_ARGUMENTS to
dump_function_decl when printing a function template instantiation as a
scope.
gcc/testsuite/ChangeLog:
PR c++/94521
* g++.dg/cpp2a/lambda-uneval12.C: New test.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/cp/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/cp/error.c | 2 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 3 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/cpp2a/lambda-uneval12.C | 13 |
4 files changed, 23 insertions, 0 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 3da61db..65b648a 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,10 @@ 2020-04-13 Patrick Palka <ppalka@redhat.com> + PR c++/94521 + * error.c (dump_scope): Pass TFF_NO_FUNCTION_ARGUMENTS to + dump_function_decl when printing a function template instantiation as a + scope. + PR c++/94470 * constexpr.c (get_or_insert_ctor_field): Set default value of parameter 'pos_hint' to -1. diff --git a/gcc/cp/error.c b/gcc/cp/error.c index 61d1218..98c163d 100644 --- a/gcc/cp/error.c +++ b/gcc/cp/error.c @@ -211,6 +211,8 @@ dump_scope (cxx_pretty_printer *pp, tree scope, int flags) } else if ((flags & TFF_SCOPE) && TREE_CODE (scope) == FUNCTION_DECL) { + if (DECL_USE_TEMPLATE (scope)) + f |= TFF_NO_FUNCTION_ARGUMENTS; dump_function_decl (pp, scope, f); pp_cxx_colon_colon (pp); } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 74a7fa1..8e2df1b 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,8 @@ 2020-04-13 Patrick Palka <ppalka@redhat.com> + PR c++/94521 + * g++.dg/cpp2a/lambda-uneval12.C: New test. + PR c++/94470 * g++.dg/cpp1y/constexpr-nsdmi8.C: New test. * g++.dg/cpp1y/constexpr-nsdmi9.C: New test. diff --git a/gcc/testsuite/g++.dg/cpp2a/lambda-uneval12.C b/gcc/testsuite/g++.dg/cpp2a/lambda-uneval12.C new file mode 100644 index 0000000..24d2e70 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/lambda-uneval12.C @@ -0,0 +1,13 @@ +// PR c++/94521 +// { dg-do compile { target c++2a } } + +template <typename T> +void spam(decltype([]{}) *s) +{ + static_assert(__is_same(int, decltype(s))); // { dg-error "static assertion failed" } +} + +void foo() +{ + spam<int>(nullptr); +} |