]> granicus.if.org Git - clang/commitdiff
[AST] Assert that no type class is polymorphic
authorBruno Ricci <riccibrun@gmail.com>
Tue, 4 Dec 2018 16:36:28 +0000 (16:36 +0000)
committerBruno Ricci <riccibrun@gmail.com>
Tue, 4 Dec 2018 16:36:28 +0000 (16:36 +0000)
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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@348281 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/Type.cpp

index bfb08c0d38909303f61ed486400b5faccdf899a2..89ab2ce1fcc75f5c7f8c6006298a6a258a90bf7b 100644 (file)
@@ -291,6 +291,14 @@ QualType QualType::getSingleStepDesugaredTypeImpl(QualType type,
   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)