From ea8aaa21e852ffcc375e4471f67817f27e57ed96 Mon Sep 17 00:00:00 2001 From: Kevin Kiningham Date: Sat, 11 Jun 2022 14:39:05 -0700 Subject: [PATCH] Fix compile error under strict C++11 mode (#3463) --- src/V3Ast.h | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/V3Ast.h b/src/V3Ast.h index 47ae4dcc0..dc4cf6d8e 100644 --- a/src/V3Ast.h +++ b/src/V3Ast.h @@ -2021,11 +2021,12 @@ private: return Default; } - template constexpr static void checkTypeParameter() { + template constexpr static bool checkTypeParameter() { static_assert(!std::is_const::value, "Type parameter 'T_Node' should not be const qualified"); static_assert(std::is_base_of::value, "Type parameter 'T_Node' must be a subtype of AstNode"); + return true; } public: @@ -2035,25 +2036,25 @@ public: // operation function in 'foreach' should be completely predictable by branch target caches in // modern CPUs, while it is basically unpredictable for VNVisitor. template void foreach (std::function f) { - checkTypeParameter(); + static_assert(checkTypeParameter(), "Invalid type parameter 'T_Node'"); foreachImpl(this, f); } // Same as above, but for 'const' nodes template void foreach (std::function f) const { - checkTypeParameter(); + static_assert(checkTypeParameter(), "Invalid type parameter 'T_Node'"); foreachImpl(this, f); } // Same as 'foreach' but also follows 'this->nextp()' template void foreachAndNext(std::function f) { - checkTypeParameter(); + static_assert(checkTypeParameter(), "Invalid type parameter 'T_Node'"); foreachImpl(this, f); } // Same as 'foreach' but also follows 'this->nextp()' template void foreachAndNext(std::function f) const { - checkTypeParameter(); + static_assert(checkTypeParameter(), "Invalid type parameter 'T_Node'"); foreachImpl(this, f); } @@ -2062,13 +2063,13 @@ public: // present. Traversal is performed in some arbitrary order and is terminated as soon as the // result can be determined. template bool exists(std::function p) { - checkTypeParameter(); + static_assert(checkTypeParameter(), "Invalid type parameter 'T_Node'"); return predicateImpl(this, p); } // Same as above, but for 'const' nodes template void exists(std::function p) const { - checkTypeParameter(); + static_assert(checkTypeParameter(), "Invalid type parameter 'T_Node'"); return predicateImpl(this, p); } @@ -2077,13 +2078,13 @@ public: // present. Traversal is performed in some arbitrary order and is terminated as soon as the // result can be determined. template bool forall(std::function p) { - checkTypeParameter(); + static_assert(checkTypeParameter(), "Invalid type parameter 'T_Node'"); return predicateImpl(this, p); } // Same as above, but for 'const' nodes template void forall(std::function p) const { - checkTypeParameter(); + static_assert(checkTypeParameter(), "Invalid type parameter 'T_Node'"); return predicateImpl(this, p); }