aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/name-lookup.c7
-rw-r--r--gcc/cp/parser.c4
-rw-r--r--gcc/testsuite/g++.dg/cpp2a/consteval-defarg1.C11
3 files changed, 21 insertions, 1 deletions
diff --git a/gcc/cp/name-lookup.c b/gcc/cp/name-lookup.c
index 837c0ea..c87d151 100644
--- a/gcc/cp/name-lookup.c
+++ b/gcc/cp/name-lookup.c
@@ -3291,12 +3291,17 @@ begin_scope (scope_kind kind, tree entity)
case sk_cond:
case sk_class:
case sk_scoped_enum:
- case sk_function_parms:
case sk_transaction:
case sk_omp:
scope->keep = keep_next_level_flag;
break;
+ case sk_function_parms:
+ scope->keep = keep_next_level_flag;
+ if (entity)
+ scope->immediate_fn_ctx_p = DECL_IMMEDIATE_FUNCTION_P (entity);
+ break;
+
case sk_namespace:
NAMESPACE_LEVEL (entity) = scope;
break;
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 52743b0..a8e86cf 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -30566,6 +30566,8 @@ cp_parser_late_parsing_default_args (cp_parser *parser, tree fn)
push_defarg_context (fn);
+ begin_scope (sk_function_parms, fn);
+
for (parm = TYPE_ARG_TYPES (TREE_TYPE (fn)),
parmdecl = DECL_ARGUMENTS (fn);
parm && parm != void_list_node;
@@ -30598,6 +30600,8 @@ cp_parser_late_parsing_default_args (cp_parser *parser, tree fn)
TREE_PURPOSE (copy) = parsed_arg;
}
+ pop_bindings_and_leave_scope ();
+
pop_defarg_context ();
/* Make sure no default arg is missing. */
diff --git a/gcc/testsuite/g++.dg/cpp2a/consteval-defarg1.C b/gcc/testsuite/g++.dg/cpp2a/consteval-defarg1.C
new file mode 100644
index 0000000..826ee25
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/consteval-defarg1.C
@@ -0,0 +1,11 @@
+// Test that late-parsed default args have the same consteval semantics.
+// { dg-do compile { target c++20 } }
+
+consteval bool foo (bool x) { if (x) throw 1; return false; }
+consteval bool bar (bool x = foo (true)) { return true; }
+struct S
+{
+ consteval static bool baz (bool x = foo (true)) { return true; }
+};
+constexpr bool a = bar (true);
+constexpr bool b = S::baz (true);