https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123695
--- Comment #3 from Boris Staletic <boris.staletic at protonmail dot com> --- On this line: https://gcc.gnu.org/git/?p=gcc.git;a=blob;f=gcc/cp/reflect.cc;h=56f36e917e95576ec439b9ac0454ea704a90cee3;hb=HEAD#l2605 In case `r` represents `^^int`, `r->typed.type` is a `NULL_TREE`. Then `TYPE_REF_P(NULL_TREE)` leads to this segfault. If it is expected to receive such a tree, then perhaps just a NULL check is enough. I have not reviewed the whole reflection.cc to see where else this might happen. Assuming it is fine to just add a null check, here's an untested patch: diff --git a/gcc/cp/reflect.cc b/gcc/cp/reflect.cc index 56f36e917e..360dd24e4c 100644 --- a/gcc/cp/reflect.cc +++ b/gcc/cp/reflect.cc @@ -2602,7 +2602,8 @@ eval_object_of (location_t loc, const constexpr_ctx *ctx, tree r, tree *jump_target, tree fun) { tree orig = r; - if (TYPE_REF_P (TREE_TYPE (r))) + tree type = TREE_TYPE (r); + if (type != NULL_TREE && TYPE_REF_P (type)) r = cxx_eval_constant_expression (ctx, r, vc_prvalue, non_constant_p, overflow_p, jump_target); r = maybe_get_reference_referent (r);
