Castable: Minor tweaks

Prefix the fully-qualified Unique name in TINT_INSTANTIATE_CLASS_ID with :: as there might (however unlikely) be a nested 'tint' namespace.

Move the test structures in castable_test back into the anonymous namespace. This means `TINT_INSTANTIATE_CLASS_ID` needs to sit outside the anonymous namespace, but prevents global namespace pollution.

Change-Id: I035e9568c081fee120726106dc2150c4990c3881
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/34567
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
Ben Clayton 2020-12-03 17:44:19 +00:00 committed by Commit Bot service account
parent f1f10e6571
commit 5f8061bd39
2 changed files with 14 additions and 11 deletions

View File

@ -24,7 +24,7 @@ namespace tint {
/// Helper macro to instantiate the ClassID for `CLASS`.
#define TINT_INSTANTIATE_CLASS_ID(CLASS) \
template <> \
const char tint::ClassID::Unique<CLASS>::token = 0
const char ::tint::ClassID::Unique<CLASS>::token = 0
/// ClassID represents a unique, comparable identifier for a C++ type.
class ClassID {

View File

@ -19,6 +19,9 @@
#include "gtest/gtest.h"
namespace tint {
namespace {
struct Animal : public tint::Castable<Animal> {
explicit Animal(std::string n) : name(n) {}
const std::string name;
@ -48,16 +51,6 @@ struct Gecko : public tint::Castable<Gecko, Reptile> {
Gecko() : Base("Gecko") {}
};
TINT_INSTANTIATE_CLASS_ID(Animal);
TINT_INSTANTIATE_CLASS_ID(Amphibian);
TINT_INSTANTIATE_CLASS_ID(Mammal);
TINT_INSTANTIATE_CLASS_ID(Reptile);
TINT_INSTANTIATE_CLASS_ID(Frog);
TINT_INSTANTIATE_CLASS_ID(Bear);
TINT_INSTANTIATE_CLASS_ID(Gecko);
namespace tint {
TEST(CastableBase, Is) {
std::unique_ptr<CastableBase> frog = std::make_unique<Frog>();
std::unique_ptr<CastableBase> bear = std::make_unique<Bear>();
@ -146,4 +139,14 @@ TEST(Castable, As) {
ASSERT_EQ(gecko->As<Reptile>(), static_cast<Reptile*>(gecko.get()));
}
} // namespace
TINT_INSTANTIATE_CLASS_ID(Animal);
TINT_INSTANTIATE_CLASS_ID(Amphibian);
TINT_INSTANTIATE_CLASS_ID(Mammal);
TINT_INSTANTIATE_CLASS_ID(Reptile);
TINT_INSTANTIATE_CLASS_ID(Frog);
TINT_INSTANTIATE_CLASS_ID(Bear);
TINT_INSTANTIATE_CLASS_ID(Gecko);
} // namespace tint