]> granicus.if.org Git - clang/commitdiff
[AST] Assert that no statement/expression class is polymorphic
authorBruno Ricci <riccibrun@gmail.com>
Tue, 4 Dec 2018 16:04:19 +0000 (16:04 +0000)
committerBruno Ricci <riccibrun@gmail.com>
Tue, 4 Dec 2018 16:04:19 +0000 (16:04 +0000)
Add a static_assert checking that no statement/expression class
is polymorphic. People should use LLVM style RTTI instead.

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

Reviewed By: aaron.ballman

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

lib/AST/Stmt.cpp

index 32330ea3bfe221be0da20089c5dd80de9144f379..116291bfa1efbdc5abc61e1e628c46fcbaf0b801 100644 (file)
@@ -76,6 +76,14 @@ const char *Stmt::getStmtClassName() const {
   return getStmtInfoTableEntry((StmtClass) StmtBits.sClass).Name;
 }
 
+// Check that no statement / expression 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 STMT(CLASS, PARENT) \
+  static_assert(!std::is_polymorphic<CLASS>::value, \
+                #CLASS " should not be polymorphic!");
+#include "clang/AST/StmtNodes.inc"
+
 void Stmt::PrintStats() {
   // Ensure the table is primed.
   getStmtInfoTableEntry(Stmt::NullStmtClass);