-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[libc++] Add exception guard for vector<bool>::__init_with_sentinel #115491
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
Merged
ldionne
merged 8 commits into
llvm:main
from
winner245:winner245/vector_bool_exception_guard
Nov 28, 2024
+162
−83
Merged
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
2220361
Add exception tests for vector<bool>
winner245 5f127ed
Add exception guard for vector<bool>::__init_with_sentinel
winner245 c8010fd
Run clang-format
winner245 f14822a
Update header guard to match the header name
winner245 d1edb2e
Fix compatibility
winner245 2cb7028
Refactor in a better way
winner245 d43d704
Use more complex header guard name for common.h
winner245 8e12408
Update libcxx/test/std/containers/sequences/vector/common.h
ldionne File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef TEST_STD_CONTAINERS_SEQUENCES_VECTOR_COMMON_H | ||
#define TEST_STD_CONTAINERS_SEQUENCES_VECTOR_COMMON_H | ||
|
||
#include <cassert> | ||
#include <cstddef> | ||
#include <memory> | ||
#include <type_traits> | ||
|
||
#include "count_new.h" | ||
|
||
template <class T> | ||
struct throwing_allocator { | ||
using value_type = T; | ||
using is_always_equal = std::false_type; | ||
|
||
bool throw_on_copy_ = false; | ||
|
||
explicit throwing_allocator(bool throw_on_ctor = true) { | ||
if (throw_on_ctor) | ||
throw 0; | ||
} | ||
|
||
explicit throwing_allocator(bool throw_on_ctor, bool throw_on_copy) : throw_on_copy_(throw_on_copy) { | ||
if (throw_on_ctor) | ||
throw 0; | ||
} | ||
|
||
throwing_allocator(const throwing_allocator& rhs) : throw_on_copy_(rhs.throw_on_copy_) { | ||
if (throw_on_copy_) | ||
throw 0; | ||
} | ||
|
||
template <class U> | ||
throwing_allocator(const throwing_allocator<U>& rhs) : throw_on_copy_(rhs.throw_on_copy_) { | ||
if (throw_on_copy_) | ||
throw 0; | ||
} | ||
|
||
T* allocate(std::size_t n) { return std::allocator<T>().allocate(n); } | ||
void deallocate(T* ptr, std::size_t n) { std::allocator<T>().deallocate(ptr, n); } | ||
|
||
template <class U> | ||
friend bool operator==(const throwing_allocator&, const throwing_allocator<U>&) { | ||
return true; | ||
} | ||
}; | ||
|
||
template <class T, class IterCat> | ||
struct throwing_iterator { | ||
using iterator_category = IterCat; | ||
using difference_type = std::ptrdiff_t; | ||
using value_type = T; | ||
using reference = T&; | ||
using pointer = T*; | ||
|
||
int i_; | ||
T v_; | ||
|
||
throwing_iterator(int i = 0, const T& v = T()) : i_(i), v_(v) {} | ||
|
||
reference operator*() { | ||
if (i_ == 1) | ||
throw 1; | ||
return v_; | ||
} | ||
|
||
friend bool operator==(const throwing_iterator& lhs, const throwing_iterator& rhs) { return lhs.i_ == rhs.i_; } | ||
friend bool operator!=(const throwing_iterator& lhs, const throwing_iterator& rhs) { return lhs.i_ != rhs.i_; } | ||
|
||
throwing_iterator& operator++() { | ||
++i_; | ||
return *this; | ||
} | ||
|
||
throwing_iterator operator++(int) { | ||
auto tmp = *this; | ||
++i_; | ||
return tmp; | ||
} | ||
}; | ||
|
||
inline void check_new_delete_called() { | ||
assert(globalMemCounter.new_called == globalMemCounter.delete_called); | ||
assert(globalMemCounter.new_array_called == globalMemCounter.delete_array_called); | ||
assert(globalMemCounter.aligned_new_called == globalMemCounter.aligned_delete_called); | ||
assert(globalMemCounter.aligned_new_array_called == globalMemCounter.aligned_delete_array_called); | ||
} | ||
|
||
#endif // COMMON_H | ||
ldionne marked this conversation as resolved.
Show resolved
Hide resolved
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.