[PATCH] D86369: [Sema][MSVC] warn at dynamic_cast when /GR- is given

Hans Wennborg via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 25 08:16:57 PDT 2020


hans added inline comments.


================
Comment at: clang/test/SemaCXX/ms_dynamic_cast.cpp:16
+    B *b = new D1();
+    auto d = dynamic_cast<D1 *>(b); // expected-warning{{should not use dynamic_cast with /GR-}}
+}
----------------
zequanwu wrote:
> lebedev.ri wrote:
> > I'm not sure it makes sense to talk about MSVC/clang-cl flags when normal clang is used.
> > Either the diag should only be used in MSVC compat mode,
> > or it should talk about `-fno-rtti` in non-MSVC compat mode.
> I am not sure either... But `-fno-rtti-data` is only used when clang-cl driver translate `/GR-` to `-fno-rtti-data`.
Instead of "should not use" maybe the warning could say something which suggests it won't work, like "dynamic_cast will not work since RTTI data is disabled" or something like that.

I'm not sure what to do about the name of the option. -fno-rtti-data was added to support clang-cl's /GR- option, but it could also be used with regular Clang. Maybe the warning doesn't need to mention the name of the flag? Or it could mention both? Or maybe it could figure out if it's in clang-cl or regular clang mode?

Also, should it also warn about typeid()?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86369



More information about the cfe-commits mailing list