Skip to content

Commit 637e623

Browse files
committed
Report a clearer error for non-integral iterator differences
1 parent 359ddfd commit 637e623

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

clang/lib/Sema/SemaStmt.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4002,7 +4002,7 @@ StmtResult Sema::BuildCilkForRangeStmt(CXXForRangeStmt *ForRange) {
40024002
}
40034003
ExprResult LimitExpr = ActOnBinOp(S, ForRange->getColonLoc(), tok::minus,
40044004
EndRef.get(), BeginRef.get());
4005-
if (LimitExpr.isInvalid()) {
4005+
if (LimitExpr.isInvalid() || !LimitExpr.get()->getType()->isIntegerType()) {
40064006
// CilkForRange currently only supports random access iterators.
40074007
Diag(ForRange->getForLoc(), diag::err_cilk_for_range_end_minus_begin);
40084008
return StmtError();
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// RUN: %clang_cc1 %s -std=c++20 -triple x86_64-unknown-linux-gnu -fopencilk -fsyntax-only -verify
2+
3+
template<class Datum>
4+
struct Iterator {
5+
void *data;
6+
Iterator operator+(long);
7+
bool operator!=(const Iterator &) const;
8+
Iterator &operator++();
9+
Datum &operator*();
10+
Datum *operator->();
11+
};
12+
13+
struct S {
14+
int data;
15+
struct I : public Iterator<S> {
16+
float operator-(const I &) const;
17+
};
18+
I begin(), end();
19+
};
20+
21+
struct T {
22+
int data;
23+
struct I : public Iterator<T> {
24+
long operator-(const I &) const;
25+
};
26+
I begin(), end();
27+
};
28+
29+
void sum(S &s, T &t) {
30+
_Cilk_for (auto i : s) { // expected-warning{{experimental}}
31+
// expected-error@-1{{cannot determine length}}
32+
}
33+
_Cilk_for (auto i : _Cilk_spawn t) { // expected-warning{{experimental}}
34+
// expected-error@-1{{'cilk_spawn' not allowed in this scope}}
35+
}
36+
}

0 commit comments

Comments
 (0)