diff options
author | Jason Merrill <jason@redhat.com> | 2021-04-05 11:34:48 -0400 |
---|---|---|
committer | Jason Merrill <jason@redhat.com> | 2021-04-05 15:37:01 -0400 |
commit | 62d60246e53778db6ee613377dd013ba4b264968 (patch) | |
tree | 05f4366d7d8b6d704f6e27515813b3773e639632 /gcc | |
parent | 7ebdef2076fda56cb4cffb941f6c2576f980f3b3 (diff) | |
download | gcc-62d60246e53778db6ee613377dd013ba4b264968.zip gcc-62d60246e53778db6ee613377dd013ba4b264968.tar.gz gcc-62d60246e53778db6ee613377dd013ba4b264968.tar.bz2 |
c++: lambda in DMI in class template [PR95870]
Here enclosing_instantiation_of was failing to find a match because otctx is
struct S<T> and current_function_decl is S<int>::S(), so the latter has more
function contexts, and we end up trying to compare S() to NULL_TREE.
After spending a bit of time working on establishing the correspondence in
this case (class <=> constructor), it occurred to me that we could just use
DECL_SOURCE_LOCATION, which is unique for lambdas, since they cannot be
redeclared. Since we're so close to release, for now I'm only doing this
for the case that was failing before.
gcc/cp/ChangeLog:
PR c++/95870
* pt.c (enclosing_instantiation_of): Compare DECL_SOURCE_LOCATION if
there is no enclosing non-lambda function.
gcc/testsuite/ChangeLog:
PR c++/95870
* g++.dg/cpp0x/lambda/lambda-nsdmi10.C: New test.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/cp/pt.c | 13 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/cpp0x/lambda/lambda-nsdmi10.C | 12 |
2 files changed, 25 insertions, 0 deletions
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 396e622..d6a8ede 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -14371,6 +14371,19 @@ enclosing_instantiation_of (tree otctx) || instantiated_lambda_fn_p (tctx)); tctx = decl_function_context (tctx)) ++lambda_count; + + if (!tctx) + { + /* Match using DECL_SOURCE_LOCATION, which is unique for all lambdas. + + For GCC 11 the above condition limits this to the previously failing + case where all enclosing functions are lambdas (95870). FIXME. */ + for (tree ofn = fn; ofn; ofn = decl_function_context (ofn)) + if (DECL_SOURCE_LOCATION (ofn) == DECL_SOURCE_LOCATION (otctx)) + return ofn; + gcc_unreachable (); + } + for (; fn; fn = decl_function_context (fn)) { tree ofn = fn; diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-nsdmi10.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-nsdmi10.C new file mode 100644 index 0000000..810ed53 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-nsdmi10.C @@ -0,0 +1,12 @@ +// PR c++/95870 +// { dg-do compile { target c++11 } } + +template <typename> struct S { + S(); + int b = []() -> int { enum E {}; return 1; }(); +}; +struct C : S<int> { + C(); +}; +template <typename T> S<T>::S() = default; +C::C() {} |