[libcxx-commits] [libcxx] [libc++] Resolve LWG4308, correct `iterator` availability for `optional<T&>` (PR #173948)
A. Jiang via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Dec 30 17:51:54 PST 2025
================
@@ -56,7 +71,11 @@ constexpr bool test() {
assert((std::is_same_v<typename decltype(it)::value_type, std::remove_cvref_t<T>>));
assert((std::is_same_v<typename decltype(it)::reference, std::remove_reference_t<T>&>));
assert((std::is_same_v<typename decltype(it2)::value_type, std::remove_cvref_t<T>>));
- assert((std::is_same_v<typename decltype(it2)::reference, const std::remove_reference_t<T>&>));
+
+ // for optional<T&>, there is no const_iterator
+ if (!std::is_lvalue_reference_v<T>) {
+ assert((std::is_same_v<typename decltype(it2)::reference, const std::remove_reference_t<T>&>));
+ }
----------------
frederick-vs-ja wrote:
Maybe pre-existing. Why aren't `if constexpr` and `static_assert` used here?
```suggestion
if constexpr (!std::is_lvalue_reference_v<T>) {
static_assert(std::is_same_v<typename decltype(it2)::reference, const std::remove_reference_t<T>&>);
}
```
https://github.com/llvm/llvm-project/pull/173948
More information about the libcxx-commits
mailing list