[PATCH] D47291: Proposal to make rtti errors more generic.

Sunil Srivastava via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed May 23 15:16:25 PDT 2018

Sunil_Srivastava created this revision.
Herald added a subscriber: cfe-commits.

This patch changes the wording of two errors to make them more generic.

An attempt to use dynamic_cast while rtti is disabled, curently emits the error:

  cannot use dynamic_cast with -fno-rtti

and a similar one for typeid.

This patch proposes to change that to:

  use of dynamic_cast requires enabling RTTI

For targets where the default mode of RTTI is disabled, the current error
message is confusing because the user never used the -fno-rtti option.

This proposal is motivated by the PS4 compiler, whose default is to have RTTI
disabled. However, it is just as clear as the existing diagnostic, and it
may be applicable to other llvm compilers having the have the same default as the
PS4 compiler. It is also more appropriate in cases where the spelling of the
argument (to disable RTTI) is something other than -fno-rtti (for
example, /GR- is the switch to disable RTTI for cl).

  rC Clang



Index: test/SemaCXX/no-rtti.cpp
--- test/SemaCXX/no-rtti.cpp
+++ test/SemaCXX/no-rtti.cpp
@@ -6,7 +6,7 @@
 void f()
-  (void)typeid(int); // expected-error {{cannot use typeid with -fno-rtti}}
+  (void)typeid(int); // expected-error {{use of typeid requires enabling RTTI}}
 namespace {
@@ -20,7 +20,7 @@
 bool isa_B(A *a) {
-  return dynamic_cast<B *>(a) != 0; // expected-error {{cannot use dynamic_cast with -fno-rtti}}
+  return dynamic_cast<B *>(a) != 0; // expected-error {{use of dynamic_cast requires enabling RTTI}}
 void* getMostDerived(A* a) {
Index: include/clang/Basic/DiagnosticSemaKinds.td
--- include/clang/Basic/DiagnosticSemaKinds.td
+++ include/clang/Basic/DiagnosticSemaKinds.td
@@ -6724,9 +6724,9 @@
   "no %select{struct|interface|union|class|enum}0 named %1 in %2">;
 def err_no_typeid_with_fno_rtti : Error<
-  "cannot use typeid with -fno-rtti">;
+  "use of typeid requires enabling RTTI">;
 def err_no_dynamic_cast_with_fno_rtti : Error<
-  "cannot use dynamic_cast with -fno-rtti">;
+  "use of dynamic_cast requires enabling 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">;

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D47291.148298.patch
Type: text/x-patch
Size: 1359 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180523/0b09909c/attachment-0001.bin>

More information about the cfe-commits mailing list