Issue 122264
Summary [clang] is it possible to make *it and ++it consistently noexcept for standard container iterators?
Labels clang
Assignees
Reporter wanghan02
    I think this is not specified in the standard. GCC and MSVC consistently make them `noexcept` for all standard containers. But clang make them `noexcept` for `std::vector`/`std::basic_string` but `noexcept(false)` for `std::list`/`std::set`/`std::map`/`std::unordered_set`/`std::unordered_map`. If they won't throw any exceptions, why not making them consistently `noexcept`?

Example code could be found below or on [godbolt](https://godbolt.org/z/z1Ex5x7Ee).

```
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <vector>
#include <list>
#include <string>
#include <ranges>

template<typename Iterator>
concept nothrow_advancable = noexcept(++std::declval<Iterator&>());

template<typename Iterator>
concept nothrow_dereferencable = noexcept(*std::declval<Iterator&>());

static_assert(nothrow_advancable<std::ranges::iterator_t<std::vector<int>&>>);
static_assert(nothrow_advancable<std::ranges::iterator_t<std::basic_string<char>&>>);
static_assert(nothrow_advancable<std::ranges::iterator_t<std::list<int>&>>); // not noexcept with clang
static_assert(nothrow_advancable<std::ranges::iterator_t<std::set<int>&>>); // not noexcept with clang
static_assert(nothrow_advancable<std::ranges::iterator_t<std::map<int, int>&>>); // not noexcept with clang
static_assert(nothrow_advancable<std::ranges::iterator_t<std::unordered_set<int>&>>); // not noexcept with clang
static_assert(nothrow_advancable<std::ranges::iterator_t<std::unordered_map<int, int>&>>); // not noexcept with clang

static_assert(nothrow_dereferencable<std::ranges::iterator_t<std::vector<int>&>>);
static_assert(nothrow_dereferencable<std::ranges::iterator_t<std::basic_string<char>&>>);
static_assert(nothrow_dereferencable<std::ranges::iterator_t<std::list<int>&>>); // not noexcept with clang
static_assert(nothrow_dereferencable<std::ranges::iterator_t<std::set<int>&>>); // not noexcept with clang
static_assert(nothrow_dereferencable<std::ranges::iterator_t<std::map<int, int>&>>); // not noexcept with clang
static_assert(nothrow_dereferencable<std::ranges::iterator_t<std::unordered_set<int>&>>); // not noexcept with clang
static_assert(nothrow_dereferencable<std::ranges::iterator_t<std::unordered_map<int, int>&>>); // not noexcept with clang
```
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to