On 3/14/22 02:36, Zhao Wei Liew via Gcc-patches wrote:

This patch adds a warning when casting "this" to Derived* in the Base
class constructor and destructor. I've added the warning under the
-Wextra flag as I can't find a more appropriate flag for it.

It's generally best to add a new warning flag if an existing one isn't a good match. Maybe -Wderived-cast-undefined? It seems like it could be part of -Wall.

+      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.

+        warning_at(loc, OPT_Wextra,

Missing space before '('.

Jason

Reply via email to