[PATCH] D19312: Warn about UB at member function calls from base class ctor initializers.

Artem Dergachev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Jul 8 17:39:43 PDT 2019


NoQ added a comment.

Sorry, couldn't help it. This patch looks so useful and so lonely :)



================
Comment at: include/clang/Basic/DiagnosticSemaKinds.td:6782
+def warn_member_call_in_ctor_init : Warning<
+  "member function call %0 in ctor-initializer for base class %1 results in "
+  "undefined behavior">,
----------------
I don't see these things referred to as "ctor-initializers" in other diagnostics. I'd rather say "initializer".

Also "has undefined behavior" is shorter and nicer.


================
Comment at: lib/Sema/SemaDeclCXX.cpp:2295
+    // or 0 if the current CXXCtorInitializer isn't initializing a base class.
+    const Type *CurrentBaseClass;
 
----------------
I'd be scared not to initialize this variable to null.

Also, this visitor scans only one constructor throughout its lifetime, right?


================
Comment at: lib/Sema/SemaDeclCXX.cpp:2588-2589
+        // is undefined behavior.
+        // As getImplicitObjectArgument() returns 0 for member pointer
+        // calls we use dyn_cast_or_null instead of isa.
+        if (dyn_cast_or_null<CXXThisExpr>(E->getImplicitObjectArgument())) {
----------------
Ugh.

This is worth a test case!


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D19312/new/

https://reviews.llvm.org/D19312





More information about the cfe-commits mailing list