Provide a Printable CRTP parent to replace HasPrintable templates. (#3166)

With the toolchain splitting namespaces, ostream.h's `operator<<`
templates aren't reliably found with name lookup, likely due to the loss
of associated namespaces (zygoloid commented on this at
https://github.com/carbon-language/carbon-lang/pull/3161#discussion_r1307941999).
This is especially a barrier to moving the lex files into `Carbon::Lex`;
versus other parts of the toolchain, they contain more printable types
which are used cross-namespace, including `Carbon::Testing`. As a
consequence, I'm looking at migrating ostream.h to a more reliable
approach that doesn't rely as much on everything being in the `Carbon`
namespace.
This commit is contained in:
Jon Ross-Perkins
2023-08-30 21:32:19 +00:00
committed by GitHub
parent 9600030a05
commit 53af8f04b2
32 changed files with 114 additions and 240 deletions
+5 -5
View File
@@ -8,7 +8,8 @@
#include "testing/base/test_raw_ostream.h"
namespace Carbon {
namespace Carbon::Testing {
namespace {
// These are directly in the Carbon namespace because the defines require it.
CARBON_DEFINE_RAW_ENUM_CLASS(TestKind, uint8_t) {
@@ -34,8 +35,8 @@ CARBON_DEFINE_ENUM_CLASS_NAMES(TestKind) = {
#include "common/enum_base_test.def"
};
namespace Testing {
namespace {
static_assert(sizeof(TestKind) == sizeof(uint8_t),
"Class size doesn't match enum size!");
TEST(EnumBaseTest, NamesAndConstants) {
EXPECT_EQ("Beep", TestKind::Beep.name());
@@ -108,5 +109,4 @@ TEST(EnumBaseTest, IntConversion) {
}
} // namespace
} // namespace Testing
} // namespace Carbon
} // namespace Carbon::Testing