}
def WebAssemblyExceptionSpec : DiagGroup<"wasm-exception-spec">;
+
+def RTTI : DiagGroup<"rtti">;
"use of typeid requires -frtti">;
def err_no_dynamic_cast_with_fno_rtti : Error<
"use of dynamic_cast requires -frtti">;
+def warn_no_dynamic_cast_with_rtti_disabled: Warning<
+ "dynamic_cast will not work since RTTI data is disabled by "
+ "%select{-fno-rtti-data|/GR-}0">, InGroup<RTTI>;
+def warn_no_typeid_with_rtti_disabled: Warning<
+ "typeid will not work since RTTI data is disabled by "
+ "%select{-fno-rtti-data|/GR-}0">, InGroup<RTTI>;
def err_cannot_form_pointer_to_member_of_reference_type : Error<
"cannot form a pointer-to-member to member %0 of reference type %1">;
return;
}
+ // Warns when dynamic_cast is used with RTTI data disabled.
+ if (!Self.getLangOpts().RTTIData) {
+ bool MicrosoftABI =
+ Self.getASTContext().getTargetInfo().getCXXABI().isMicrosoft();
+ bool isClangCL = Self.getDiagnostics().getDiagnosticOptions().getFormat() ==
+ DiagnosticOptions::MSVC;
+ if (MicrosoftABI || !DestPointee->isVoidType())
+ Self.Diag(OpRange.getBegin(),
+ diag::warn_no_dynamic_cast_with_rtti_disabled)
+ << isClangCL;
+ }
+
// Done. Everything else is run-time checks.
Kind = CK_Dynamic;
}
return ExprError(Diag(OpLoc, diag::err_no_typeid_with_fno_rtti));
}
+ // Warns when typeid is used with RTTI data disabled.
+ if (!getLangOpts().RTTIData)
+ Diag(OpLoc, diag::warn_no_typeid_with_rtti_disabled)
+ << (getDiagnostics().getDiagnosticOptions().getFormat() ==
+ DiagnosticOptions::MSVC);
+
QualType TypeInfoType = Context.getTypeDeclType(CXXTypeInfoDecl);
if (isType) {
--- /dev/null
+// RUN: %clang_cc1 %s -triple x86_64-windows -fdiagnostics-format msvc -fno-rtti-data -fsyntax-only -verify
+
+namespace std {
+struct type_info {};
+} // namespace std
+class B {
+public:
+ virtual ~B() = default;
+};
+
+class D1 : public B {
+public:
+ ~D1() = default;
+};
+
+void f() {
+ B* b = new D1();
+ auto d = dynamic_cast<D1 *>(b); // expected-warning{{dynamic_cast will not work since RTTI data is disabled by /GR-}}
+ void* v = dynamic_cast<void *>(b); // expected-warning{{dynamic_cast will not work since RTTI data is disabled by /GR-}}
+ (void)typeid(int); // expected-warning{{typeid will not work since RTTI data is disabled by /GR-}}
+}
--- /dev/null
+// RUN: %clang_cc1 %s -fno-rtti-data -fsyntax-only -verify
+
+namespace std {
+struct type_info {};
+} // namespace std
+class B {
+public:
+ virtual ~B() = default;
+};
+
+class D1 : public B {
+public:
+ ~D1() = default;
+};
+
+void f() {
+ B* b = new D1();
+ auto d = dynamic_cast<D1 *>(b); // expected-warning{{dynamic_cast will not work since RTTI data is disabled by -fno-rtti-data}}
+ void* v = dynamic_cast<void *>(b);
+ (void)typeid(int); // expected-warning{{typeid will not work since RTTI data is disabled by -fno-rtti-data}}
+}