-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[libc++] Disallow character types being index types of extents
#105832
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
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e33f05f
[libc++] Disallow character types being index types of `extents`
frederick-vs-ja ce597c3
Merge branch 'main' into extents-mandates
frederick-vs-ja 6ffb69d
Try to avoid regex in the expected-error
frederick-vs-ja 2eaa12c
Replace `char` with `signed char` in `libcxx/containers/views/mdspan`…
frederick-vs-ja e998394
Clang-format `assert.ctor_from_array.pass.cpp`
frederick-vs-ja 0db680a
Merge branch 'main' into extents-mandates
frederick-vs-ja 647aa43
Fix `assert.size.pass.cpp`
frederick-vs-ja 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
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
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
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
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
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
49 changes: 49 additions & 0 deletions
49
libcxx/test/std/containers/views/mdspan/extents/index_type.verify.cpp
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,49 @@ | ||||||||||||||||||||||||||||
// | ||||||||||||||||||||||||||||
// 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 | ||||||||||||||||||||||||||||
// | ||||||||||||||||||||||||||||
//===----------------------------------------------------------------------===// | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20 | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
// <mdspan> | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
// template<class IndexType, size_t... Extents> | ||||||||||||||||||||||||||||
// class extents; | ||||||||||||||||||||||||||||
// | ||||||||||||||||||||||||||||
// Mandates: | ||||||||||||||||||||||||||||
// - IndexType is a signed or unsigned integer type, and | ||||||||||||||||||||||||||||
// - each element of Extents is either equal to dynamic_extent, or is representable as a value of type IndexType. | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
#include <cstddef> | ||||||||||||||||||||||||||||
#include <climits> | ||||||||||||||||||||||||||||
#include <mdspan> | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
void invalid_index_types() { | ||||||||||||||||||||||||||||
// expected-error@*:* {{static assertion failed: extents::index_type must be a signed or unsigned integer type}} | ||||||||||||||||||||||||||||
[[maybe_unused]] std::extents<char, '*'> ec; | ||||||||||||||||||||||||||||
#ifndef TEST_HAS_NO_CHAR8_T | ||||||||||||||||||||||||||||
// expected-error@*:* {{static assertion failed: extents::index_type must be a signed or unsigned integer type}} | ||||||||||||||||||||||||||||
[[maybe_unused]] std::extents<char8_t, u8'*'> ec8; | ||||||||||||||||||||||||||||
#endif | ||||||||||||||||||||||||||||
// expected-error@*:* {{static assertion failed: extents::index_type must be a signed or unsigned integer type}} | ||||||||||||||||||||||||||||
[[maybe_unused]] std::extents<char16_t, u'*'> ec16; | ||||||||||||||||||||||||||||
// expected-error@*:* {{static assertion failed: extents::index_type must be a signed or unsigned integer type}} | ||||||||||||||||||||||||||||
[[maybe_unused]] std::extents<char32_t, U'*'> ec32; | ||||||||||||||||||||||||||||
#ifndef TEST_HAS_NO_WIDE_CHARACTERS | ||||||||||||||||||||||||||||
// expected-error@*:* {{static assertion failed: extents::index_type must be a signed or unsigned integer type}} | ||||||||||||||||||||||||||||
[[maybe_unused]] std::extents<wchar_t, L'*'> ewc; | ||||||||||||||||||||||||||||
#endif | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
void invalid_extent_values() { | ||||||||||||||||||||||||||||
// expected-error-re@*:* {{static assertion failed {{.*}}extents ctor: arguments must be representable as index_type and nonnegative}} | ||||||||||||||||||||||||||||
[[maybe_unused]] std::extents<signed char, static_cast<std::size_t>(SCHAR_MAX) + 1> esc1; | ||||||||||||||||||||||||||||
// expected-error-re@*:* {{static assertion failed {{.*}}extents ctor: arguments must be representable as index_type and nonnegative}} | ||||||||||||||||||||||||||||
[[maybe_unused]] std::extents<signed char, std::dynamic_extent - 1> esc2; | ||||||||||||||||||||||||||||
// expected-error-re@*:* {{static assertion failed {{.*}}extents ctor: arguments must be representable as index_type and nonnegative}} | ||||||||||||||||||||||||||||
[[maybe_unused]] std::extents<unsigned char, static_cast<std::size_t>(UCHAR_MAX) + 1> euc1; | ||||||||||||||||||||||||||||
// expected-error-re@*:* {{static assertion failed {{.*}}extents ctor: arguments must be representable as index_type and nonnegative}} | ||||||||||||||||||||||||||||
[[maybe_unused]] std::extents<unsigned char, std::dynamic_extent - 1> euc2; | ||||||||||||||||||||||||||||
Comment on lines
+41
to
+48
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
I don't know whether this is actually better. Just a thought. |
||||||||||||||||||||||||||||
} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I'd just add the appropriate
-Wno-whatever
flag to avoid the[[maybe_unused]]
. They are quite noisy IMO.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd still like to see this addressed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I might have merged a bit too hastily. @frederick-vs-ja do you think you can make a follow-up PR?