Skip to content

Commit 3ce0749

Browse files
committedSep 5, 2018
[XRay] Use a function to return a constant
We do this instead of using static constexpr char arrays because MSVC 2015 cannot handle the constant initialisation of those along with the out-of-line storage declaration. This is a follow-up to D51672. llvm-svn: 341479
1 parent 31f2517 commit 3ce0749

File tree

1 file changed

+14
-20
lines changed

1 file changed

+14
-20
lines changed
 

‎llvm/unittests/XRay/FDRRecordPrinterTest.cpp

+14-20
Original file line numberDiff line numberDiff line change
@@ -26,82 +26,76 @@ template <> struct Helper<BufferExtents> {
2626
return make_unique<BufferExtents>(1);
2727
}
2828

29-
static constexpr char Expected[] = "<Buffer: size = 1 bytes>";
29+
static const char *expected() { return "<Buffer: size = 1 bytes>"; }
3030
};
31-
const char Helper<BufferExtents>::Expected[];
3231

3332
template <> struct Helper<WallclockRecord> {
3433
static std::unique_ptr<Record> construct() {
3534
return make_unique<WallclockRecord>(1, 2);
3635
}
3736

38-
static constexpr char Expected[] = "<Wall Time: seconds = 1.000002>";
37+
static const char *expected() { return "<Wall Time: seconds = 1.000002>"; }
3938
};
40-
const char Helper<WallclockRecord>::Expected[];
4139

4240
template <> struct Helper<NewCPUIDRecord> {
4341
static std::unique_ptr<Record> construct() {
4442
return make_unique<NewCPUIDRecord>(1);
4543
}
4644

47-
static constexpr char Expected[] = "<CPU ID: 1>";
45+
static const char *expected() { return "<CPU ID: 1>"; }
4846
};
49-
const char Helper<NewCPUIDRecord>::Expected[];
5047

5148
template <> struct Helper<TSCWrapRecord> {
5249
static std::unique_ptr<Record> construct() {
5350
return make_unique<TSCWrapRecord>(1);
5451
}
5552

56-
static constexpr char Expected[] = "<TSC Wrap: base = 1>";
53+
static const char *expected() { return "<TSC Wrap: base = 1>"; }
5754
};
58-
const char Helper<TSCWrapRecord>::Expected[];
5955

6056
template <> struct Helper<CustomEventRecord> {
6157
static std::unique_ptr<Record> construct() {
6258
return make_unique<CustomEventRecord>(4, 1, "data");
6359
}
6460

65-
static constexpr char Expected[] =
66-
"<Custom Event: tsc = 1, size = 4, data = 'data'>";
61+
static const char *expected() {
62+
return "<Custom Event: tsc = 1, size = 4, data = 'data'>";
63+
}
6764
};
68-
const char Helper<CustomEventRecord>::Expected[];
6965

7066
template <> struct Helper<CallArgRecord> {
7167
static std::unique_ptr<Record> construct() {
7268
return make_unique<CallArgRecord>(1);
7369
}
7470

75-
static constexpr char Expected[] = "<Call Argument: data = 1 (hex = 0x1)>";
71+
static const char *expected() {
72+
return "<Call Argument: data = 1 (hex = 0x1)>";
73+
}
7674
};
77-
const char Helper<CallArgRecord>::Expected[];
7875

7976
template <> struct Helper<PIDRecord> {
8077
static std::unique_ptr<Record> construct() {
8178
return make_unique<PIDRecord>(1);
8279
}
8380

84-
static constexpr char Expected[] = "<PID: 1>";
81+
static const char *expected() { return "<PID: 1>"; }
8582
};
86-
const char Helper<PIDRecord>::Expected[];
8783

8884
template <> struct Helper<NewBufferRecord> {
8985
static std::unique_ptr<Record> construct() {
9086
return make_unique<NewBufferRecord>(1);
9187
}
9288

93-
static constexpr char Expected[] = "<Thread ID: 1>";
89+
static const char *expected() { return "<Thread ID: 1>"; }
9490
};
95-
const char Helper<NewBufferRecord>::Expected[];
9691

9792
template <> struct Helper<EndBufferRecord> {
9893
static std::unique_ptr<Record> construct() {
9994
return make_unique<EndBufferRecord>();
10095
}
10196

102-
static constexpr char Expected[] = "<End of Buffer>";
97+
static const char *expected() { return "<End of Buffer>"; }
10398
};
104-
const char Helper<EndBufferRecord>::Expected[];
10599

106100
template <class T> class PrinterTest : public ::testing::Test {
107101
protected:
@@ -120,7 +114,7 @@ TYPED_TEST_P(PrinterTest, PrintsRecord) {
120114
ASSERT_NE(nullptr, this->R);
121115
ASSERT_FALSE(errorToBool(this->R->apply(this->P)));
122116
this->OS.flush();
123-
EXPECT_THAT(this->Data, Eq(Helper<TypeParam>::Expected));
117+
EXPECT_THAT(this->Data, Eq(Helper<TypeParam>::expected()));
124118
}
125119

126120
REGISTER_TYPED_TEST_CASE_P(PrinterTest, PrintsRecord);

0 commit comments

Comments
 (0)
Please sign in to comment.