From 5f8061bd39bd2a13980584f7a1f96723458df994 Mon Sep 17 00:00:00 2001 From: Ben Clayton Date: Thu, 3 Dec 2020 17:44:19 +0000 Subject: [PATCH] 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 Reviewed-by: dan sinclair --- src/castable.h | 2 +- src/castable_test.cc | 23 +++++++++++++---------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/castable.h b/src/castable.h index 0740b1fa18..1eb2cbc8e0 100644 --- a/src/castable.h +++ b/src/castable.h @@ -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::token = 0 + const char ::tint::ClassID::Unique::token = 0 /// ClassID represents a unique, comparable identifier for a C++ type. class ClassID { diff --git a/src/castable_test.cc b/src/castable_test.cc index c591049113..c2b9d7ea6a 100644 --- a/src/castable_test.cc +++ b/src/castable_test.cc @@ -19,6 +19,9 @@ #include "gtest/gtest.h" +namespace tint { +namespace { + struct Animal : public tint::Castable { explicit Animal(std::string n) : name(n) {} const std::string name; @@ -48,16 +51,6 @@ struct Gecko : public tint::Castable { 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 frog = std::make_unique(); std::unique_ptr bear = std::make_unique(); @@ -146,4 +139,14 @@ TEST(Castable, As) { ASSERT_EQ(gecko->As(), static_cast(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