[llvm] [llvm] Make TestData compatible with c++20 (PR #143801)

Paul Kirth via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 11 15:58:28 PDT 2025


https://github.com/ilovepi created https://github.com/llvm/llvm-project/pull/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

>From dee6d1a6442657e0b4066954cb4d634d671a6109 Mon Sep 17 00:00:00 2001
From: Paul Kirth <paulkirth at google.com>
Date: Wed, 11 Jun 2025 15:52:48 -0700
Subject: [PATCH] [llvm] Make TestData compatible with c++20

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
---
 .../llvm-test-mustache-spec.cpp               | 20 ++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)

diff --git a/llvm/utils/llvm-test-mustache-spec/llvm-test-mustache-spec.cpp b/llvm/utils/llvm-test-mustache-spec/llvm-test-mustache-spec.cpp
index 28ed1b876672d..1f566e13f070a 100644
--- a/llvm/utils/llvm-test-mustache-spec/llvm-test-mustache-spec.cpp
+++ b/llvm/utils/llvm-test-mustache-spec/llvm-test-mustache-spec.cpp
@@ -146,6 +146,13 @@ static const StringMap<StringSet<>> XFailTestNames = {{
 }};
 
 struct TestData {
+  TestData() = default;
+  explicit TestData(const json::Object &TestCase)
+      : TemplateStr(*TestCase.getString("template")),
+        ExpectedStr(*TestCase.getString("expected")),
+        Name(*TestCase.getString("name")), Data(TestCase.get("data")),
+        Partials(TestCase.get("partials")) {}
+
   static Expected<TestData> createTestData(json::Object *TestCase,
                                            StringRef InputFile) {
     // If any of the needed elements are missing, we cannot continue.
@@ -157,19 +164,14 @@ struct TestData {
           llvm::inconvertibleErrorCode(),
           "invalid JSON schema in test file: " + InputFile + "\n");
 
-    return TestData{TestCase->getString("template").value(),
-                    TestCase->getString("expected").value(),
-                    TestCase->getString("name").value(), TestCase->get("data"),
-                    TestCase->get("partials")};
+    return TestData(*TestCase);
   }
 
-  TestData() = default;
-
   StringRef TemplateStr;
   StringRef ExpectedStr;
   StringRef Name;
-  Value *Data;
-  Value *Partials;
+  const Value *Data;
+  const Value *Partials;
 };
 
 static void reportTestFailure(const TestData &TD, StringRef ActualStr,
@@ -191,7 +193,7 @@ static void reportTestFailure(const TestData &TD, StringRef ActualStr,
   }
 }
 
-static void registerPartials(Value *Partials, Template &T) {
+static void registerPartials(const Value *Partials, Template &T) {
   if (!Partials)
     return;
   for (const auto &[Partial, Str] : *Partials->getAsObject())



More information about the llvm-commits mailing list