[tint] static_assert that C in Castable<C[, B]> is correct

Fix a bug this caught.

Fixed: tint:1939
Change-Id: I61ea4eb66fe1f91b3bc17ba5d65aee7324aa555c
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/132621
Auto-Submit: Ben Clayton <bclayton@google.com>
Reviewed-by: James Price <jrprice@google.com>
Commit-Queue: James Price <jrprice@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
This commit is contained in:
Ben Clayton 2023-05-12 12:00:06 +00:00 committed by Dawn LUCI CQ
parent 6ac063d568
commit b0726080f4
2 changed files with 10 additions and 5 deletions

View File

@ -133,7 +133,7 @@ class Statement : public utils::Castable<Statement, Node> {
/// CompoundStatement is the base class of statements that can hold other
/// statements.
class CompoundStatement : public utils::Castable<Statement, Statement> {
class CompoundStatement : public utils::Castable<CompoundStatement, Statement> {
public:
/// Constructor
/// @param declaration the AST node for this statement

View File

@ -18,6 +18,7 @@
#include <stdint.h>
#include <functional>
#include <tuple>
#include <type_traits>
#include <utility>
#include "src/tint/utils/crc32.h"
@ -73,7 +74,9 @@ static constexpr bool IsCastable =
tint::utils::TypeInfo::HashCodeOf<CLASS>(), \
tint::utils::TypeInfo::FullHashCodeOf<CLASS>(), \
}; \
TINT_CASTABLE_POP_DISABLE_WARNINGS()
TINT_CASTABLE_POP_DISABLE_WARNINGS(); \
static_assert(std::is_same_v<CLASS, CLASS::Base::Class>, \
#CLASS " does not derive from Castable<" #CLASS "[, BASE]>")
/// Bit flags that can be passed to the template parameter `FLAGS` of Is() and As().
enum CastFlags {
@ -414,14 +417,16 @@ class CastableBase {
template <typename CLASS, typename BASE = CastableBase>
class Castable : public BASE {
public:
/// A type alias for `CLASS` to easily access the `BASE` class members.
/// Base actually aliases to the Castable instead of `BASE` so that you can
/// use Base in the `CLASS` constructor.
/// A type alias to this Castable. Commonly used in derived type constructors to forward
/// constructor arguments to BASE.
using Base = Castable;
/// A type alias for `BASE`.
using TrueBase = BASE;
/// A type alias for `CLASS`.
using Class = CLASS;
/// Constructor
/// @param arguments the arguments to forward to the base class.
template <typename... ARGS>