diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index c0a37a51cba3c815c49460e36394795fdcdad96c..c9219d5b3a5ae0fe0e5ba723a96d8c0526820973 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -13480,7 +13480,12 @@ extract_locals_r (tree *tp, int *walk_subtrees, void *data_) outermost tree. Nested *_EXTRA_ARGS should naturally be empty since the outermost (extra-args) tree will intercept any substitution before a nested tree can. */ - gcc_checking_assert (tree_extra_args (*tp) == NULL_TREE); + gcc_checking_assert (tree_extra_args (*tp) == NULL_TREE + /* Except a lambda nested inside an extra-args tree + can have extra args if we deferred partial + substitution into it at template parse time. But + we don't walk LAMBDA_EXPR_EXTRA_ARGS anyway. */ + || TREE_CODE (*tp) == LAMBDA_EXPR); if (TREE_CODE (*tp) == DECL_EXPR) { diff --git a/gcc/testsuite/g++.dg/cpp2a/lambda-targ9.C b/gcc/testsuite/g++.dg/cpp2a/lambda-targ9.C new file mode 100644 index 0000000000000000000000000000000000000000..41f8526184a8a9903f181b7800bdc7dfc6eea608 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/lambda-targ9.C @@ -0,0 +1,16 @@ +// PR c++/117054 +// { dg-do compile { target c++20 } } + +template<auto = []{}> +constexpr bool v = true; + +template<typename> +void f() { + [](auto) { + if constexpr (v<>) { } + }(0); +} + +int main() { + f<int>(); +}