On 3/27/22 08:37, Zhao Wei Liew wrote:
On Fri, 25 Mar 2022 at 05:58, Jason Merrill <ja...@redhat.com> wrote:
+ if (current_function_decl
+ && (DECL_CONSTRUCTOR_P (current_function_decl)
+ || DECL_DESTRUCTOR_P (current_function_decl))
+ && TREE_CODE (expr) == NOP_EXPR
+ && is_this_parameter (TREE_OPERAND (expr, 0)))
I think the resolves_to_fixed_type_p function would be useful here;
you're testing for a subset of the cases it handles.
Does the new patch look like how you intended it to? The new patch
passes all regression tests and newly added tests. However, I don't
fully understand the code for resolves_to_fixed_type_p() and
fixed_type_or_null(), except that I see that they contain logic to
return -1 when within a ctor/dtor.
+ if (TREE_CODE (expr) == NOP_EXPR
+ && resolves_to_fixed_type_p (TREE_OPERAND (expr, 0)) == -1)
Why not just pass expr itself to resolves_to_fixed_type_p?
You're right. I didn't realise that fixed_type_or_null handles the
NOP_EXPR case as part of CASE_CONVERT.
We might as well also warn if it returns >0, e.g.
struct A { } a;
struct B: A { };
auto p = static_cast<B*>(&a); // undefined
You should also handle reference casts.
I've made some changes in v3 to handle reference casts and the case
where resolves_to_fixed_type_p > 0. I've also slightly modified the
patch title to reflect the new changes.
Looks good, I've queued this for when GCC 13 development opens.
Thanks,
Jason