[libcxx-commits] [PATCH] D131929: [libcxx] Resolve warnings for Wimplicit-float-conversion, Wmacro-redefined, Wzero-as-null-pointer-constant, Wsign-conversion

Dominic Chen via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Tue Aug 16 15:30:24 PDT 2022


ddcc added inline comments.


================
Comment at: libcxx/include/string_view:288
     typedef ptrdiff_t                                  difference_type;
-    static _LIBCPP_CONSTEXPR const size_type npos = -1; // size_type(-1);
+    static _LIBCPP_CONSTEXPR const size_type npos = ~static_cast<size_type>(0U); // size_type(-1);
 
----------------
ddcc wrote:
> philnik wrote:
> > Maybe use numeric_limits here instead?
> Will do.
Hmm looks like numeric_limits just moves the problem: 
```
warning: signed shift result (0x8000000000000000) sets the sign bit of the shift expression's type ('long') and becomes negative [-Wshift-sign-overflow]
    static _LIBCPP_CONSTEXPR const _Tp value = _Tp(_Tp(1) << __digits);
```

Two alternatives come to mind; either we suppress the warning here, or we do something similar to the following (for e.g. int64_t):
```
-static_cast<uint64_t>((1ULL << (sizeof(int64_t) * CHAR_BITS - 1) - 1)
```


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D131929/new/

https://reviews.llvm.org/D131929



More information about the libcxx-commits mailing list