diff options
author | Max Graey <maxgraey@gmail.com> | 2020-10-09 00:36:58 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-08 14:36:58 -0700 |
commit | d68896d8c54f538c04d4fe43825a63ba135ed0fe (patch) | |
tree | e7b376a1903b864a357b9a2e151e72668d2a00d1 | |
parent | e433611dbef8dd83e48fc9402f8ad3fce63c3690 (diff) | |
download | binaryen-d68896d8c54f538c04d4fe43825a63ba135ed0fe.tar.gz binaryen-d68896d8c54f538c04d4fe43825a63ba135ed0fe.tar.bz2 binaryen-d68896d8c54f538c04d4fe43825a63ba135ed0fe.zip |
Add static guards for cast and dynCast (#3201)
-rw-r--r-- | src/wasm.h | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/src/wasm.h b/src/wasm.h index 0a4c0db16..024a8dd06 100644 --- a/src/wasm.h +++ b/src/wasm.h @@ -585,22 +585,34 @@ public: void finalize() {} - template<class T> bool is() const { return int(_id) == int(T::SpecificId); } + template<class T> bool is() const { + static_assert(std::is_base_of<Expression, T>::value, + "Expression is not a base of destination type T"); + return int(_id) == int(T::SpecificId); + } template<class T> T* dynCast() { + static_assert(std::is_base_of<Expression, T>::value, + "Expression is not a base of destination type T"); return int(_id) == int(T::SpecificId) ? (T*)this : nullptr; } template<class T> const T* dynCast() const { + static_assert(std::is_base_of<Expression, T>::value, + "Expression is not a base of destination type T"); return int(_id) == int(T::SpecificId) ? (const T*)this : nullptr; } template<class T> T* cast() { + static_assert(std::is_base_of<Expression, T>::value, + "Expression is not a base of destination type T"); assert(int(_id) == int(T::SpecificId)); return (T*)this; } template<class T> const T* cast() const { + static_assert(std::is_base_of<Expression, T>::value, + "Expression is not a base of destination type T"); assert(int(_id) == int(T::SpecificId)); return (const T*)this; } |