[libcxx-commits] [libcxx] [libc++][test] Raise a useful error when no -std=c++NN flag is found to work (PR #99423)

Janet Cobb via libcxx-commits libcxx-commits at lists.llvm.org
Wed Jul 17 20:07:08 PDT 2024


https://github.com/randomnetcat created https://github.com/llvm/llvm-project/pull/99423

Recently ran into an issue with symptoms very similar to https://github.com/llvm/llvm-project/issues/56816 while attempting to build and test libc++ on NixOS. The error message is cryptic (just `StopIteration`), which was very annoying to track down. The error at least saying "hey your compiler's bad" would have saved me quite a bit of time figuring out the issue.

>From 33db30b634a81c869f4ee53c42a629e681c3c57c Mon Sep 17 00:00:00 2001
From: Janet Cobb <git at randomcat.org>
Date: Wed, 17 Jul 2024 23:03:52 -0400
Subject: [PATCH] Raise a useful error when no -std=c++NN flag is detected

---
 libcxx/utils/libcxx/test/params.py | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/libcxx/utils/libcxx/test/params.py b/libcxx/utils/libcxx/test/params.py
index 3aadc54cf92dc..320d550a0dc50 100644
--- a/libcxx/utils/libcxx/test/params.py
+++ b/libcxx/utils/libcxx/test/params.py
@@ -87,6 +87,15 @@ def getStdFlag(cfg, std):
         return "-std=" + fallbacks[std]
     return None
 
+def getDefaultStdValue(cfg):
+    viable = [s for s in reversed(_allStandards) if getStdFlag(cfg, s)]
+
+    if not viable:
+        raise RuntimeError(
+            "Unable to successfully detect the presence of any -std=c++NN flag. This likely indicates an issue with your compiler."
+        )
+
+    return viable[0]
 
 def getSpeedOptimizationFlag(cfg):
     if _isClang(cfg) or _isAppleClang(cfg) or _isGCC(cfg):
@@ -170,9 +179,7 @@ def getSuitableClangTidy(cfg):
         choices=_allStandards,
         type=str,
         help="The version of the standard to compile the test suite with.",
-        default=lambda cfg: next(
-            s for s in reversed(_allStandards) if getStdFlag(cfg, s)
-        ),
+        default=lambda cfg: getDefaultStdValue(cfg),
         actions=lambda std: [
             AddFeature(std),
             AddSubstitution("%{cxx_std}", re.sub(r"\+", "x", std)),



More information about the libcxx-commits mailing list