aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2025-04-04 17:34:08 -0400
committerJason Merrill <jason@redhat.com>2025-04-04 23:37:53 -0400
commit7d561820525fd3b9d8f3876333c0584d75e7c053 (patch)
tree02d0d09e475211b0a993a65f1d00b964a3095fbb
parent2f62e66e1444d858e937faa7147f6cd06296b33b (diff)
downloadgcc-7d561820525fd3b9d8f3876333c0584d75e7c053.zip
gcc-7d561820525fd3b9d8f3876333c0584d75e7c053.tar.gz
gcc-7d561820525fd3b9d8f3876333c0584d75e7c053.tar.bz2
c++: __FUNCTION__ in lambda return type [PR118629]
In this testcase, the use of __FUNCTION__ is within a function parameter scope, the lambda's. And P1787 changed __func__ to live in the parameter scope. But [basic.scope.pdecl] says that the point of declaration of __func__ is immediately before {, so in the trailing return type it isn't in scope yet, so this __FUNCTION__ should refer to foo(). Looking first for a block scope, then a function parameter scope, gives us the right result. PR c++/118629 gcc/cp/ChangeLog: * name-lookup.cc (pushdecl_outermost_localscope): Look for an sk_block. gcc/testsuite/ChangeLog: * g++.dg/cpp0x/lambda/lambda-__func__3.C: New test.
-rw-r--r--gcc/cp/name-lookup.cc8
-rw-r--r--gcc/testsuite/g++.dg/cpp0x/lambda/lambda-__func__3.C6
2 files changed, 11 insertions, 3 deletions
diff --git a/gcc/cp/name-lookup.cc b/gcc/cp/name-lookup.cc
index 7fadbcc..1cd982e 100644
--- a/gcc/cp/name-lookup.cc
+++ b/gcc/cp/name-lookup.cc
@@ -5204,9 +5204,11 @@ pushdecl_outermost_localscope (tree x)
cp_binding_level *b = NULL;
auto_cond_timevar tv (TV_NAME_LOOKUP);
- /* Find the scope just inside the function parms. */
- for (cp_binding_level *n = current_binding_level;
- n->kind != sk_function_parms; n = b->level_chain)
+ /* Find the block scope just inside the function parms. */
+ cp_binding_level *n = current_binding_level;
+ while (n && n->kind != sk_block)
+ n = n->level_chain;
+ for (; n && n->kind != sk_function_parms; n = b->level_chain)
b = n;
return b ? do_pushdecl_with_scope (x, b) : error_mark_node;
diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-__func__3.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-__func__3.C
new file mode 100644
index 0000000..50ad6e5
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-__func__3.C
@@ -0,0 +1,6 @@
+// PR c++/118629
+// { dg-do compile { target c++11 } }
+
+void foo() {
+ []() -> decltype(+__FUNCTION__) { return nullptr; };
+}