Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[libc++] is it possible to make *it and ++it consistently noexcept for standard container iterators? #122264

Open
wanghan02 opened this issue Jan 9, 2025 · 0 comments
Labels
libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. question A question, not bug report. Check out https://llvm.org/docs/GettingInvolved.html instead!

Comments

@wanghan02
Copy link

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.

#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
@llvmbot llvmbot added the clang Clang issues not falling into any other category label Jan 9, 2025
@frederick-vs-ja frederick-vs-ja added question A question, not bug report. Check out https://llvm.org/docs/GettingInvolved.html instead! libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. and removed clang Clang issues not falling into any other category labels Jan 9, 2025
@philnik777 philnik777 changed the title [clang] is it possible to make *it and ++it consistently noexcept for standard container iterators? [libc++] is it possible to make *it and ++it consistently noexcept for standard container iterators? Jan 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. question A question, not bug report. Check out https://llvm.org/docs/GettingInvolved.html instead!
Projects
None yet
Development

No branches or pull requests

3 participants