-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Avoid truncation warnings for contiguous iterators with unusual diffe…
…rence types (#4898) Co-authored-by: Stephan T. Lavavej <[email protected]>
- Loading branch information
1 parent
20a1c9f
commit d5777f4
Showing
4 changed files
with
43 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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 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
4 changes: 4 additions & 0 deletions
4
tests/std/tests/GH_003663_cast_contiguous_iterator_difference_type/env.lst
This file contains 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,4 @@ | ||
# Copyright (c) Microsoft Corporation. | ||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
||
RUNALL_INCLUDE ..\usual_20_matrix.lst |
36 changes: 36 additions & 0 deletions
36
tests/std/tests/GH_003663_cast_contiguous_iterator_difference_type/test.compile.pass.cpp
This file contains 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,36 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
||
#include <algorithm> | ||
#include <iterator> | ||
|
||
class ContiguousIterator { | ||
public: | ||
using value_type = int; | ||
using difference_type = int; | ||
using element_type = int; | ||
using iterator_category = std::contiguous_iterator_tag; | ||
int* operator->() const; | ||
int& operator*() const; | ||
int& operator[](int) const; | ||
ContiguousIterator& operator++(); | ||
ContiguousIterator operator++(int); | ||
ContiguousIterator& operator--(); | ||
ContiguousIterator operator--(int); | ||
ContiguousIterator& operator+=(int); | ||
ContiguousIterator& operator-=(int); | ||
friend auto operator<=>(ContiguousIterator, ContiguousIterator) = default; | ||
friend int operator-(ContiguousIterator, ContiguousIterator); | ||
friend ContiguousIterator operator+(ContiguousIterator, int); | ||
friend ContiguousIterator operator-(ContiguousIterator, int); | ||
friend ContiguousIterator operator+(int, ContiguousIterator); | ||
}; | ||
|
||
static_assert(std::contiguous_iterator<ContiguousIterator>); | ||
|
||
// GH-3663 <algorithm>/<iterator>: contiguous iterators with non-ptrdiff_t difference types | ||
void test() { | ||
int* p = nullptr; | ||
std::copy(p, p, ContiguousIterator{}); | ||
std::sort(ContiguousIterator{}, ContiguousIterator{}); | ||
} |