Skip to content

Commit a26aac4

Browse files
ilovepitomtor
authored andcommitted
[llvm] Make TestData compatible with c++20 (llvm#143801)
The clang-debian-cpp20 buildbot did not like direct initialization without a matching constructor. This patch adds a new constructor taking a json::Object that directly initializes the struct fields. We also update an internal interface for const correctness. https://lab.llvm.org/buildbot/#/builders/108/builds/13950
1 parent 3a70839 commit a26aac4

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

llvm/utils/llvm-test-mustache-spec/llvm-test-mustache-spec.cpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,13 @@ static const StringMap<StringSet<>> XFailTestNames = {{
146146
}};
147147

148148
struct TestData {
149+
TestData() = default;
150+
explicit TestData(const json::Object &TestCase)
151+
: TemplateStr(*TestCase.getString("template")),
152+
ExpectedStr(*TestCase.getString("expected")),
153+
Name(*TestCase.getString("name")), Data(TestCase.get("data")),
154+
Partials(TestCase.get("partials")) {}
155+
149156
static Expected<TestData> createTestData(json::Object *TestCase,
150157
StringRef InputFile) {
151158
// If any of the needed elements are missing, we cannot continue.
@@ -157,19 +164,14 @@ struct TestData {
157164
llvm::inconvertibleErrorCode(),
158165
"invalid JSON schema in test file: " + InputFile + "\n");
159166

160-
return TestData{TestCase->getString("template").value(),
161-
TestCase->getString("expected").value(),
162-
TestCase->getString("name").value(), TestCase->get("data"),
163-
TestCase->get("partials")};
167+
return TestData(*TestCase);
164168
}
165169

166-
TestData() = default;
167-
168170
StringRef TemplateStr;
169171
StringRef ExpectedStr;
170172
StringRef Name;
171-
Value *Data;
172-
Value *Partials;
173+
const Value *Data;
174+
const Value *Partials;
173175
};
174176

175177
static void reportTestFailure(const TestData &TD, StringRef ActualStr,
@@ -191,7 +193,7 @@ static void reportTestFailure(const TestData &TD, StringRef ActualStr,
191193
}
192194
}
193195

194-
static void registerPartials(Value *Partials, Template &T) {
196+
static void registerPartials(const Value *Partials, Template &T) {
195197
if (!Partials)
196198
return;
197199
for (const auto &[Partial, Str] : *Partials->getAsObject())

0 commit comments

Comments
 (0)