[libcxx-commits] [libcxx] [libc++][hardening] Categorize more assertions. (PR #75918)

Konstantin Varlamov via libcxx-commits libcxx-commits at lists.llvm.org
Thu Jan 4 19:14:17 PST 2024


================
@@ -4587,28 +4587,36 @@ public:
 
   // element access:
   _LIBCPP_HIDE_FROM_ABI difference_type length(size_type __sub = 0) const {
-    _LIBCPP_ASSERT_UNCATEGORIZED(ready(), "match_results::length() called when not ready");
+    // If the match results are not ready, this will return `0`.
+    _LIBCPP_ASSERT_PEDANTIC(ready(), "match_results::length() called when not ready");
----------------
var-const wrote:

Hmm, this is exactly the sort of situation for which I intended the new "pedantic" category (perhaps the name could be improved?). These are always triggered by user input (otherwise it would have to be classified as `internal`). It returns a "reasonable" default value (by reasonable, I mean that if, for the sake of the argument, we wanted to make this situation well-defined, that's the value we would probably return in this situation -- not saying it would be a good idea, just hypothetically); we cannot say for sure whether that value would cause any problems.

I suppose it could be argued that `pedantic` could only be used for no-ops (and thus not for any function returning a value). We don't currently have a category to capture "returns an incorrect value but we don't know if it leads to any problems since that's purely on the user's side". We would probably need something like that, but IMO "pedantic" is reasonable here since this is as close to a no-op as possible for a function returning a value. Perhaps renaming "pedantic" would improve things?

https://github.com/llvm/llvm-project/pull/75918


More information about the libcxx-commits mailing list