{
tree decl;
tree class_type = NULL_TREE;
+ tree class_type_fields = NULL_TREE;
tree pushed_scope = NULL_TREE;
unsigned ix;
cp_default_arg_entry *e;
vec_safe_truncate (unparsed_funs_with_definitions, 0);
}
+ auto switch_to_class = [&] (tree t)
+ {
+ if (class_type != t)
+ {
+ /* cp_parser_late_parsing_default_args etc. could have changed
+ TYPE_FIELDS (class_type), propagate that to all variants. */
+ if (class_type
+ && RECORD_OR_UNION_TYPE_P (class_type)
+ && TYPE_FIELDS (class_type) != class_type_fields)
+ for (tree variant = TYPE_NEXT_VARIANT (class_type);
+ variant; variant = TYPE_NEXT_VARIANT (variant))
+ TYPE_FIELDS (variant) = TYPE_FIELDS (class_type);
+ if (pushed_scope)
+ pop_scope (pushed_scope);
+ class_type = t;
+ class_type_fields = NULL_TREE;
+ if (t)
+ {
+ if (RECORD_OR_UNION_TYPE_P (class_type))
+ class_type_fields = TYPE_FIELDS (class_type);
+ pushed_scope = push_scope (class_type);
+ }
+ else
+ pushed_scope = NULL_TREE;
+ }
+ };
+
/* In a first pass, parse default arguments to the functions.
Then, in a second pass, parse the bodies of the functions.
This two-phased approach handles cases like:
decl = e->decl;
/* If there are default arguments that have not yet been processed,
take care of them now. */
- if (class_type != e->class_type)
- {
- if (pushed_scope)
- pop_scope (pushed_scope);
- class_type = e->class_type;
- pushed_scope = push_scope (class_type);
- }
+ switch_to_class (e->class_type);
/* Make sure that any template parameters are in scope. */
maybe_begin_member_template_processing (decl);
/* Parse the default argument expressions. */
FOR_EACH_VEC_SAFE_ELT (unparsed_noexcepts, ix, decl)
{
tree ctx = DECL_CONTEXT (decl);
- if (class_type != ctx)
- {
- if (pushed_scope)
- pop_scope (pushed_scope);
- class_type = ctx;
- pushed_scope = push_scope (class_type);
- }
+ switch_to_class (ctx);
tree def_parse = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (decl));
def_parse = TREE_PURPOSE (def_parse);
/* Now parse any NSDMIs. */
FOR_EACH_VEC_SAFE_ELT (unparsed_nsdmis, ix, decl)
{
- if (class_type != DECL_CONTEXT (decl))
- {
- if (pushed_scope)
- pop_scope (pushed_scope);
- class_type = DECL_CONTEXT (decl);
- pushed_scope = push_scope (class_type);
- }
+ switch_to_class (DECL_CONTEXT (decl));
inject_this_parameter (class_type, TYPE_UNQUALIFIED);
cp_parser_late_parsing_nsdmi (parser, decl);
}
vec_safe_truncate (unparsed_nsdmis, 0);
current_class_ptr = NULL_TREE;
current_class_ref = NULL_TREE;
- if (pushed_scope)
- pop_scope (pushed_scope);
+ switch_to_class (NULL_TREE);
/* Now parse the body of the functions. */
if (flag_openmp)
--- /dev/null
+// PR c++/98533
+// { dg-do compile { target c++11 } }
+// { dg-options "-g" }
+
+class IR;
+struct Pass {
+ explicit Pass(IR *ir) : ir_(ir) {}
+ virtual ~Pass() = default;
+ IR *ir_ {nullptr};
+};
+struct PassManager {
+ template <typename T> void RunPass() { T pass(ir_); }
+ IR *ir_ {nullptr};
+};
+struct IR final {
+ template <typename T> void RunPass() { pass_manager_.RunPass<T>(); }
+ PassManager pass_manager_;
+};
+struct ThePass : Pass {
+ explicit ThePass(IR *ir) : Pass(ir) {}
+ ThePass(const ThePass &) = delete;
+ template <typename Func = bool (*)(void *)> void Bar(void *inst, Func func = [](void *) {});
+};
+
+void foo(IR *ir) { ir->RunPass<ThePass>(); }