You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
wanghan02 opened this issue
Jan 9, 2025
· 0 comments
Labels
libc++libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.questionA question, not bug report. Check out https://llvm.org/docs/GettingInvolved.html instead!
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?
#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
The text was updated successfully, but these errors were encountered:
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
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
libc++libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.questionA question, not bug report. Check out https://llvm.org/docs/GettingInvolved.html instead!
I think this is not specified in the standard. GCC and MSVC consistently make them
noexcept
for all standard containers. But clang make themnoexcept
forstd::vector
/std::basic_string
butnoexcept(false)
forstd::list
/std::set
/std::map
/std::unordered_set
/std::unordered_map
. If they won't throw any exceptions, why not making them consistentlynoexcept
?Example code could be found below or on godbolt.
The text was updated successfully, but these errors were encountered: