[PATCH] D55225: [AST] Assert that no type class is polymorphic

Bruno Ricci via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Dec 3 08:10:00 PST 2018


riccibruno created this revision.
riccibruno added a reviewer: aaron.ballman.
riccibruno added a project: clang.
Herald added a subscriber: cfe-commits.

Add a `static_assert` checking that no type class is polymorphic.
People should use LLVM style RTTI instead.


Repository:
  rC Clang

https://reviews.llvm.org/D55225

Files:
  lib/AST/Type.cpp


Index: lib/AST/Type.cpp
===================================================================
--- lib/AST/Type.cpp
+++ lib/AST/Type.cpp
@@ -291,6 +291,14 @@
   return Context.getQualifiedType(desugar, split.Quals);
 }
 
+// Check that no type class is polymorphic. LLVM style RTTI should be used
+// instead. If absolutely needed an exception can still be added here by
+// defining the appropriate macro (but please don't do this).
+#define TYPE(CLASS, BASE) \
+  static_assert(!std::is_polymorphic<CLASS##Type>::value, \
+                #CLASS "Type should not be polymorphic!");
+#include "clang/AST/TypeNodes.def"
+
 QualType Type::getLocallyUnqualifiedSingleStepDesugaredType() const {
   switch (getTypeClass()) {
 #define ABSTRACT_TYPE(Class, Parent)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D55225.176414.patch
Type: text/x-patch
Size: 757 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20181203/0a9fc0b1/attachment.bin>


More information about the cfe-commits mailing list