[committed] libstdc++: Fix constant_wrapper compile-time test for COW strings.

Tomasz Kamiński tkaminsk@redhat.com
Tue Apr 14 12:35:11 GMT 2026


Throwing std::invalid_argument at compile time is only supported for
SSO strings, replaced with custom class.

libstdc++-v3/ChangeLog:

	* testsuite/20_util/constant_wrapper/generic.cc: Replace
	std::std::invalid_argument with NegativeArgument and
	removed <stdexcept> include.
---
On last minute decided to replace throw 10, with something more meanigfull,
and forgot about the COW string limitation.

Pushed to trunk.

 .../testsuite/20_util/constant_wrapper/generic.cc     | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/libstdc++-v3/testsuite/20_util/constant_wrapper/generic.cc b/libstdc++-v3/testsuite/20_util/constant_wrapper/generic.cc
index 7538efead49..bd41fc4ca3a 100644
--- a/libstdc++-v3/testsuite/20_util/constant_wrapper/generic.cc
+++ b/libstdc++-v3/testsuite/20_util/constant_wrapper/generic.cc
@@ -2,7 +2,6 @@
 #include <functional>
 #include <utility>
 #include <string_view>
-#include <stdexcept>
 
 #include <testsuite_hooks.h>
 
@@ -172,13 +171,15 @@ struct MoveArgFunc
   { return arg.v; }
 };
 
+struct NegativeArgument {};
+
 struct ThrowFunc
 {
   static constexpr int
   operator()(int i, int j)
   {
     if (i < 0 || j < 0)
-      throw std::invalid_argument("negative");
+      throw NegativeArgument();
     return i + j;
   }
 };
@@ -249,7 +250,7 @@ test_function_object()
   try {
     std::cw<ThrowFunc{}>(std::cw<-1>, std::cw<1>);
     VERIFY(false);
-  } catch (const std::invalid_argument&) {
+  } catch (const NegativeArgument&) {
     VERIFY(true);
   }
 }
@@ -322,7 +323,7 @@ struct ThrowIndex
   operator[](int i, int j)
   {
     if (i < 0 || j < 0)
-      throw std::invalid_argument("negative");
+      throw NegativeArgument();
     return i * j;
   }
 };
@@ -391,7 +392,7 @@ test_indexable1()
   try {
     std::cw<ThrowIndex{}>[std::cw<-1>, std::cw<1>];
     VERIFY(false);
-  } catch (const std::invalid_argument&) {
+  } catch (const NegativeArgument&) {
     VERIFY(true);
   }
 }
-- 
2.53.0



More information about the Libstdc++ mailing list