r348281 - [AST] Assert that no type class is polymorphic

Bruno Ricci via cfe-commits cfe-commits at lists.llvm.org
Tue Dec 4 08:36:28 PST 2018


Author: brunoricci
Date: Tue Dec  4 08:36:28 2018
New Revision: 348281

URL: http://llvm.org/viewvc/llvm-project?rev=348281&view=rev
Log:
[AST] Assert that no type class is polymorphic

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

Differential Revision: https://reviews.llvm.org/D55225

Reviewed By: aaron.ballman


Modified:
    cfe/trunk/lib/AST/Type.cpp

Modified: cfe/trunk/lib/AST/Type.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Type.cpp?rev=348281&r1=348280&r2=348281&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Type.cpp (original)
+++ cfe/trunk/lib/AST/Type.cpp Tue Dec  4 08:36:28 2018
@@ -291,6 +291,14 @@ QualType QualType::getSingleStepDesugare
   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)




More information about the cfe-commits mailing list