[libc++] Avoid overloaded operator, for (T, Iter) cases#161049
Merged
frederick-vs-ja merged 9 commits intollvm:mainfrom Nov 10, 2025
Merged
[libc++] Avoid overloaded operator, for (T, Iter) cases#161049frederick-vs-ja merged 9 commits intollvm:mainfrom
operator, for (T, Iter) cases#161049frederick-vs-ja merged 9 commits intollvm:mainfrom
Conversation
Member
|
@llvm/pr-subscribers-libcxx Author: A. Jiang (frederick-vs-ja) ChangesExisting deleted overloads in Fixes #160732. Full diff: https://github.com/llvm/llvm-project/pull/161049.diff 7 Files Affected:
diff --git a/libcxx/include/__random/piecewise_constant_distribution.h b/libcxx/include/__random/piecewise_constant_distribution.h
index c5bfa8dc3a4be..bd624fffd7f0e 100644
--- a/libcxx/include/__random/piecewise_constant_distribution.h
+++ b/libcxx/include/__random/piecewise_constant_distribution.h
@@ -190,7 +190,7 @@ piecewise_constant_distribution<_RealType>::param_type::param_type(
__areas_.assign(1, 0.0);
} else {
__densities_.reserve(__b_.size() - 1);
- for (size_t __i = 0; __i < __b_.size() - 1; ++__i, ++__f_w)
+ for (size_t __i = 0; __i < __b_.size() - 1; ++__i, (void)++__f_w)
__densities_.push_back(*__f_w);
__init();
}
diff --git a/libcxx/include/__random/piecewise_linear_distribution.h b/libcxx/include/__random/piecewise_linear_distribution.h
index a9906430c005c..1ceef77c8716b 100644
--- a/libcxx/include/__random/piecewise_linear_distribution.h
+++ b/libcxx/include/__random/piecewise_linear_distribution.h
@@ -194,7 +194,7 @@ piecewise_linear_distribution<_RealType>::param_type::param_type(
__areas_.assign(1, 0.0);
} else {
__densities_.reserve(__b_.size());
- for (size_t __i = 0; __i < __b_.size(); ++__i, ++__f_w)
+ for (size_t __i = 0; __i < __b_.size(); ++__i, (void)++__f_w)
__densities_.push_back(*__f_w);
__init();
}
diff --git a/libcxx/test/std/numerics/rand/rand.dist/rand.dist.samp/rand.dist.samp.pconst/ctor_iterator.pass.cpp b/libcxx/test/std/numerics/rand/rand.dist/rand.dist.samp/rand.dist.samp.pconst/ctor_iterator.pass.cpp
index ea6e807ca47b5..46decd7d974ee 100644
--- a/libcxx/test/std/numerics/rand/rand.dist/rand.dist.samp/rand.dist.samp.pconst/ctor_iterator.pass.cpp
+++ b/libcxx/test/std/numerics/rand/rand.dist/rand.dist.samp/rand.dist.samp.pconst/ctor_iterator.pass.cpp
@@ -21,15 +21,17 @@
#include <cassert>
#include <vector>
+#include "test_iterators.h"
#include "test_macros.h"
int main(int, char**)
{
{
typedef std::piecewise_constant_distribution<> D;
+ typedef cpp17_input_iterator<const double*> InIt;
double b[] = {10};
double p[] = {12};
- D d(b, b, p);
+ D d(InIt(b), InIt(b), InIt(p));
std::vector<double> iv = d.intervals();
assert(iv.size() == 2);
assert(iv[0] == 0);
diff --git a/libcxx/test/std/numerics/rand/rand.dist/rand.dist.samp/rand.dist.samp.pconst/param_ctor_iterator.pass.cpp b/libcxx/test/std/numerics/rand/rand.dist/rand.dist.samp/rand.dist.samp.pconst/param_ctor_iterator.pass.cpp
index baf6108b7e2e8..8cb42391925a7 100644
--- a/libcxx/test/std/numerics/rand/rand.dist/rand.dist.samp/rand.dist.samp.pconst/param_ctor_iterator.pass.cpp
+++ b/libcxx/test/std/numerics/rand/rand.dist/rand.dist.samp/rand.dist.samp.pconst/param_ctor_iterator.pass.cpp
@@ -20,6 +20,7 @@
#include <cassert>
#include <vector>
+#include "test_iterators.h"
#include "test_macros.h"
int main(int, char**)
@@ -27,9 +28,10 @@ int main(int, char**)
{
typedef std::piecewise_constant_distribution<> D;
typedef D::param_type P;
+ typedef cpp17_input_iterator<const double*> InIt;
double b[] = {10};
double p[] = {12};
- P pa(b, b, p);
+ P pa(InIt(b), InIt(b), InIt(p));
std::vector<double> iv = pa.intervals();
assert(iv.size() == 2);
assert(iv[0] == 0);
diff --git a/libcxx/test/std/numerics/rand/rand.dist/rand.dist.samp/rand.dist.samp.plinear/ctor_iterator.pass.cpp b/libcxx/test/std/numerics/rand/rand.dist/rand.dist.samp/rand.dist.samp.plinear/ctor_iterator.pass.cpp
index 24f7d4e18c36a..084538dfb5156 100644
--- a/libcxx/test/std/numerics/rand/rand.dist/rand.dist.samp/rand.dist.samp.plinear/ctor_iterator.pass.cpp
+++ b/libcxx/test/std/numerics/rand/rand.dist/rand.dist.samp/rand.dist.samp.plinear/ctor_iterator.pass.cpp
@@ -21,15 +21,17 @@
#include <cassert>
#include <vector>
+#include "test_iterators.h"
#include "test_macros.h"
int main(int, char**)
{
{
typedef std::piecewise_linear_distribution<> D;
+ typedef cpp17_input_iterator<const double*> InIt;
double b[] = {10};
double p[] = {12};
- D d(b, b, p);
+ D d(InIt(b), InIt(b), InIt(p));
std::vector<double> iv = d.intervals();
assert(iv.size() == 2);
assert(iv[0] == 0);
diff --git a/libcxx/test/std/numerics/rand/rand.dist/rand.dist.samp/rand.dist.samp.plinear/param_ctor_iterator.pass.cpp b/libcxx/test/std/numerics/rand/rand.dist/rand.dist.samp/rand.dist.samp.plinear/param_ctor_iterator.pass.cpp
index 04ded2a1c9706..42754456e0d6d 100644
--- a/libcxx/test/std/numerics/rand/rand.dist/rand.dist.samp/rand.dist.samp.plinear/param_ctor_iterator.pass.cpp
+++ b/libcxx/test/std/numerics/rand/rand.dist/rand.dist.samp/rand.dist.samp.plinear/param_ctor_iterator.pass.cpp
@@ -20,6 +20,7 @@
#include <cassert>
#include <vector>
+#include "test_iterators.h"
#include "test_macros.h"
int main(int, char**)
@@ -27,9 +28,10 @@ int main(int, char**)
{
typedef std::piecewise_linear_distribution<> D;
typedef D::param_type P;
+ typedef cpp17_input_iterator<const double*> InIt;
double b[] = {10};
double p[] = {12};
- P pa(b, b, p);
+ P pa(InIt(b), InIt(b), InIt(p));
std::vector<double> iv = pa.intervals();
assert(iv.size() == 2);
assert(iv[0] == 0);
diff --git a/libcxx/test/support/test_iterators.h b/libcxx/test/support/test_iterators.h
index 0335a4c561017..006b27c10b3f0 100644
--- a/libcxx/test/support/test_iterators.h
+++ b/libcxx/test/support/test_iterators.h
@@ -109,6 +109,9 @@ class cpp17_input_iterator
template <class T>
void operator,(T const &) = delete;
+
+ template <class T>
+ friend void operator,(const T&, const cpp17_input_iterator&) = delete;
};
#if TEST_STD_VER > 14
template <class It>
|
operator, for piecewise_*_distributionoperator, for (T, Iter) cases
921abbf to
113870d
Compare
Several components in libc++ aren't defending against overloaded `operator,(T, Iter)` currently. Existing deleted overloads in `test_iterators.h` are insufficient for such cases. This PR adds corresponding deleted overloads with reversed order and fixes these libc++ components. - `piecewise_linear_distribution`'s iterator pair constructor, - `piecewise_linear_distribution::param_type`'s iterator pair constructor, - `piecewise_constant_distribution`'s iterator pair constructor, - `piecewise_constant_distribution::param_type`'s iterator pair constructor, - `money_get::do_get`, - `money_put::do_put`, and - `num_put::do_put`.
113870d to
b7ad08c
Compare
philnik777
reviewed
Nov 7, 2025
Contributor
philnik777
left a comment
There was a problem hiding this comment.
I think we should try to forward to the algorithms here if we have to touch these lines anyways. I'm fine with replacing them either in this patch or in a predecessor.
libcxx/test/std/containers/sequences/deque/deque.cons/iter_iter.pass.cpp
Outdated
Show resolved
Hide resolved
philnik777
approved these changes
Nov 10, 2025
ckoparkar
added a commit
to ckoparkar/llvm-project
that referenced
this pull request
Nov 10, 2025
* main: (1028 commits) [clang][DebugInfo] Attach `DISubprogram` to additional call variants (llvm#166202) [C2y] Claim nonconformance to WG14 N3348 (llvm#166966) [X86] 2012-01-10-UndefExceptionEdge.ll - regenerate test checks (llvm#167307) Remove unused standard headers: <string>, <optional>, <numeric>, <tuple> (llvm#167232) [DebugInfo] Add Verifier check for incorrectly-scoped retainedNodes (llvm#166855) [VPlan] Don't apply predication discount to non-originally-predicated blocks (llvm#160449) [libc++] Avoid overloaded `operator,` for (`T`, `Iter`) cases (llvm#161049) [tools][llc] Make save-stats.ll test target independent (llvm#167238) [AArch64] Fallback to PRFUM for PRFM with negative or unaligned offset (llvm#166756) [X86] ldexp-avx512.ll - add v8f16/v16f16/v32f16 test coverage for llvm#165694 (llvm#167294) [DropAssumes] Drop dereferenceable assumptions after vectorization. (llvm#166947) [VPlan] Simplify branch-cond with getVectorTripCount (llvm#155604) Remove unused <algorithm> inclusion (llvm#166942) [AArch64] Combine subtract with borrow to SBC. (llvm#165271) [AArch64][SVE] Avoid redundant extend of unsigned i8/i16 extracts. (llvm#165863) [SPIRV] Fix failing assertion in SPIRVAsmPrinter (llvm#166909) [libc++] Merge insert/emplace(const_iterator, Args...) implementations (llvm#166470) [libc++] Replace __libcpp_is_final with a variable template (llvm#167137) [gn build] Port 152bda7 [libc++] Replace the last uses of __tuple_types with __type_list (llvm#167214) ...
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Several components in libc++ aren't defending against overloaded
operator,(T, Iter)currently. Existing deleted overloads intest_iterators.hare insufficient for such cases.This PR adds corresponding deleted overloads with reversed order and fixes these libc++ components.
piecewise_linear_distribution's iterator pair constructor,piecewise_linear_distribution::param_type's iterator pair constructor,piecewise_constant_distribution's iterator pair constructor,piecewise_constant_distribution::param_type's iterator pair constructor,money_get::do_get,money_put::do_put, andnum_put::do_put.Fixes #160732.