Skip to content

Commit

Permalink
Change do...while...next to do...next...while
Browse files Browse the repository at this point in the history
*Breaking change:* `do`...`while`...`next` seems like it should be spelled (and operate as) `do`...`next`...`while` to be easier to reason about

Also:
- The default message for bounds checks might as well mention the attempted/actual bounds.
- Pretty-printing `assert` should have a `;`
  • Loading branch information
hsutter committed Dec 7, 2023
1 parent faacec0 commit b41f60e
Show file tree
Hide file tree
Showing 23 changed files with 132 additions and 111 deletions.
16 changes: 8 additions & 8 deletions regression-tests/pure2-break-continue.cpp2
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,11 @@ do_continue_inner: () =
}
std::cout << "inner ";
}
while j<3 next j++;
next j++ while j<3;

std::cout << "outer ";
}
while i<3 next i++;
next i++ while i<3;
}

do_continue_outer: () =
Expand All @@ -112,11 +112,11 @@ do_continue_outer: () =
}
std::cout << "inner ";
}
while j<3 next j++;
next j++ while j<3;

std::cout << "outer ";
}
while i<3 next i++;
next i++ while i<3;
}

do_break_inner: () =
Expand All @@ -131,11 +131,11 @@ do_break_inner: () =
}
std::cout << "inner ";
}
while j<3 next j++;
next j++ while j<3;

std::cout << "outer ";
}
while i<3 next i++;
next i++ while i<3;
}

do_break_outer: () =
Expand All @@ -150,11 +150,11 @@ do_break_outer: () =
}
std::cout << "inner ";
}
while j<3 next j++;
next j++ while j<3;

std::cout << "outer ";
}
while i<3 next i++;
next i++ while i<3;
}

for_continue_inner: () =
Expand Down
2 changes: 1 addition & 1 deletion regression-tests/pure2-intro-example-three-loops.cpp2
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ main: () -> int = {

do {
std::cout << std::setw(4) << "**";
} while i* > 1 next i*--;
} next i*-- while i*>0;

std::cout << "\n";
for words do (inout word)
Expand Down
2 changes: 1 addition & 1 deletion regression-tests/pure2-print.cpp2
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ outer: @print type = {

while s.empty() next a() { break; }

do { } while s.empty() next b();
do { } next b() while s.empty();

label: for m next c() do (_) { continue label; }

Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Bounds safety violation: out of bounds access attempt detected
Bounds safety violation: out of bounds access attempt detected - attempted index 5, [min,max] range is [0,4]
Original file line number Diff line number Diff line change
@@ -1,118 +1,118 @@
mixed-bugfix-for-ufcs-non-local.cpp2:13:12: error: a lambda expression cannot appear in this context
template<t<CPP2_UFCS_NONLOCAL(f)(o)> _> bool inline constexpr v0 = false;// Fails on GCC ([GCC109781][]) and Clang 12 (a lambda expression cannot appear in this context)
^
../../../include/cpp2util.h:856:59: note: expanded from macro 'CPP2_UFCS_NONLOCAL'
../../../include/cpp2util.h:857:59: note: expanded from macro 'CPP2_UFCS_NONLOCAL'
#define CPP2_UFCS_NONLOCAL(...) CPP2_UFCS_(,(),,__VA_ARGS__)
^
../../../include/cpp2util.h:837:53: note: expanded from macro 'CPP2_UFCS_'
../../../include/cpp2util.h:838:53: note: expanded from macro 'CPP2_UFCS_'
#define CPP2_UFCS_(LAMBDADEFCAPT,QUALID,TEMPKW,...) \
^
mixed-bugfix-for-ufcs-non-local.cpp2:15:3: error: a lambda expression cannot appear in this context
t<CPP2_UFCS_NONLOCAL(f)(o)> inline constexpr v1 = t<true>();// Fails on Clang 12 (lambda in unevaluated context).
^
../../../include/cpp2util.h:856:59: note: expanded from macro 'CPP2_UFCS_NONLOCAL'
../../../include/cpp2util.h:857:59: note: expanded from macro 'CPP2_UFCS_NONLOCAL'
#define CPP2_UFCS_NONLOCAL(...) CPP2_UFCS_(,(),,__VA_ARGS__)
^
../../../include/cpp2util.h:837:53: note: expanded from macro 'CPP2_UFCS_'
../../../include/cpp2util.h:838:53: note: expanded from macro 'CPP2_UFCS_'
#define CPP2_UFCS_(LAMBDADEFCAPT,QUALID,TEMPKW,...) \
^
mixed-bugfix-for-ufcs-non-local.cpp2:21:12: error: a lambda expression cannot appear in this context
template<t<CPP2_UFCS_NONLOCAL(f)(o)> _> auto g() -> void;
^
../../../include/cpp2util.h:856:59: note: expanded from macro 'CPP2_UFCS_NONLOCAL'
../../../include/cpp2util.h:857:59: note: expanded from macro 'CPP2_UFCS_NONLOCAL'
#define CPP2_UFCS_NONLOCAL(...) CPP2_UFCS_(,(),,__VA_ARGS__)
^
../../../include/cpp2util.h:837:53: note: expanded from macro 'CPP2_UFCS_'
../../../include/cpp2util.h:838:53: note: expanded from macro 'CPP2_UFCS_'
#define CPP2_UFCS_(LAMBDADEFCAPT,QUALID,TEMPKW,...) \
^
mixed-bugfix-for-ufcs-non-local.cpp2:23:36: error: a lambda expression cannot appear in this context
auto g([[maybe_unused]] cpp2::in<t<CPP2_UFCS_NONLOCAL(f)(o)>> unnamed_param_1) -> void;
^
../../../include/cpp2util.h:856:59: note: expanded from macro 'CPP2_UFCS_NONLOCAL'
../../../include/cpp2util.h:857:59: note: expanded from macro 'CPP2_UFCS_NONLOCAL'
#define CPP2_UFCS_NONLOCAL(...) CPP2_UFCS_(,(),,__VA_ARGS__)
^
../../../include/cpp2util.h:837:53: note: expanded from macro 'CPP2_UFCS_'
../../../include/cpp2util.h:838:53: note: expanded from macro 'CPP2_UFCS_'
#define CPP2_UFCS_(LAMBDADEFCAPT,QUALID,TEMPKW,...) \
^
mixed-bugfix-for-ufcs-non-local.cpp2:27:29: error: a lambda expression cannot appear in this context
[[nodiscard]] auto h() -> t<CPP2_UFCS_NONLOCAL(f)(o)>;
^
../../../include/cpp2util.h:856:59: note: expanded from macro 'CPP2_UFCS_NONLOCAL'
../../../include/cpp2util.h:857:59: note: expanded from macro 'CPP2_UFCS_NONLOCAL'
#define CPP2_UFCS_NONLOCAL(...) CPP2_UFCS_(,(),,__VA_ARGS__)
^
../../../include/cpp2util.h:837:53: note: expanded from macro 'CPP2_UFCS_'
../../../include/cpp2util.h:838:53: note: expanded from macro 'CPP2_UFCS_'
#define CPP2_UFCS_(LAMBDADEFCAPT,QUALID,TEMPKW,...) \
^
mixed-bugfix-for-ufcs-non-local.cpp2:31:12: error: a lambda expression cannot appear in this context
template<t<CPP2_UFCS_NONLOCAL(f)(o)> _> using a = bool;// Fails on GCC ([GCC109781][]) and Clang 12 (a lambda expression cannot appear in this context)
^
../../../include/cpp2util.h:856:59: note: expanded from macro 'CPP2_UFCS_NONLOCAL'
../../../include/cpp2util.h:857:59: note: expanded from macro 'CPP2_UFCS_NONLOCAL'
#define CPP2_UFCS_NONLOCAL(...) CPP2_UFCS_(,(),,__VA_ARGS__)
^
../../../include/cpp2util.h:837:53: note: expanded from macro 'CPP2_UFCS_'
../../../include/cpp2util.h:838:53: note: expanded from macro 'CPP2_UFCS_'
#define CPP2_UFCS_(LAMBDADEFCAPT,QUALID,TEMPKW,...) \
^
mixed-bugfix-for-ufcs-non-local.cpp2:33:12: error: a lambda expression cannot appear in this context
template<t<CPP2_UFCS_NONLOCAL(f)(o)> _> auto inline constexpr b = false;// Fails on GCC ([GCC109781][]).
^
../../../include/cpp2util.h:856:59: note: expanded from macro 'CPP2_UFCS_NONLOCAL'
../../../include/cpp2util.h:857:59: note: expanded from macro 'CPP2_UFCS_NONLOCAL'
#define CPP2_UFCS_NONLOCAL(...) CPP2_UFCS_(,(),,__VA_ARGS__)
^
../../../include/cpp2util.h:837:53: note: expanded from macro 'CPP2_UFCS_'
../../../include/cpp2util.h:838:53: note: expanded from macro 'CPP2_UFCS_'
#define CPP2_UFCS_(LAMBDADEFCAPT,QUALID,TEMPKW,...) \
^
mixed-bugfix-for-ufcs-non-local.cpp2:35:13: error: a lambda expression cannot appear in this context
using c = t<CPP2_UFCS_NONLOCAL(f)(o)>;// Fails on Clang 12 (lambda in unevaluated context) and Clang 12 (a lambda expression cannot appear in this context)
^
../../../include/cpp2util.h:856:59: note: expanded from macro 'CPP2_UFCS_NONLOCAL'
../../../include/cpp2util.h:857:59: note: expanded from macro 'CPP2_UFCS_NONLOCAL'
#define CPP2_UFCS_NONLOCAL(...) CPP2_UFCS_(,(),,__VA_ARGS__)
^
../../../include/cpp2util.h:837:53: note: expanded from macro 'CPP2_UFCS_'
../../../include/cpp2util.h:838:53: note: expanded from macro 'CPP2_UFCS_'
#define CPP2_UFCS_(LAMBDADEFCAPT,QUALID,TEMPKW,...) \
^
mixed-bugfix-for-ufcs-non-local.cpp2:37:29: error: a lambda expression cannot appear in this context
auto inline constexpr d = t<CPP2_UFCS_NONLOCAL(f)(o)>();// Fails on Clang 12 (lambda in unevaluated context).
^
../../../include/cpp2util.h:856:59: note: expanded from macro 'CPP2_UFCS_NONLOCAL'
../../../include/cpp2util.h:857:59: note: expanded from macro 'CPP2_UFCS_NONLOCAL'
#define CPP2_UFCS_NONLOCAL(...) CPP2_UFCS_(,(),,__VA_ARGS__)
^
../../../include/cpp2util.h:837:53: note: expanded from macro 'CPP2_UFCS_'
../../../include/cpp2util.h:838:53: note: expanded from macro 'CPP2_UFCS_'
#define CPP2_UFCS_(LAMBDADEFCAPT,QUALID,TEMPKW,...) \
^
mixed-bugfix-for-ufcs-non-local.cpp2:21:12: error: a lambda expression cannot appear in this context
template<t<CPP2_UFCS_NONLOCAL(f)(o)> _> auto g() -> void{}// Fails on GCC ([GCC109781][]) and Clang 12 (a lambda expression cannot appear in this context)
^
../../../include/cpp2util.h:856:59: note: expanded from macro 'CPP2_UFCS_NONLOCAL'
../../../include/cpp2util.h:857:59: note: expanded from macro 'CPP2_UFCS_NONLOCAL'
#define CPP2_UFCS_NONLOCAL(...) CPP2_UFCS_(,(),,__VA_ARGS__)
^
../../../include/cpp2util.h:837:53: note: expanded from macro 'CPP2_UFCS_'
../../../include/cpp2util.h:838:53: note: expanded from macro 'CPP2_UFCS_'
#define CPP2_UFCS_(LAMBDADEFCAPT,QUALID,TEMPKW,...) \
^
mixed-bugfix-for-ufcs-non-local.cpp2:23:36: error: a lambda expression cannot appear in this context
auto g([[maybe_unused]] cpp2::in<t<CPP2_UFCS_NONLOCAL(f)(o)>> unnamed_param_1) -> void{}// Fails on Clang 12 (lambda in unevaluated context).
^
../../../include/cpp2util.h:856:59: note: expanded from macro 'CPP2_UFCS_NONLOCAL'
../../../include/cpp2util.h:857:59: note: expanded from macro 'CPP2_UFCS_NONLOCAL'
#define CPP2_UFCS_NONLOCAL(...) CPP2_UFCS_(,(),,__VA_ARGS__)
^
../../../include/cpp2util.h:837:53: note: expanded from macro 'CPP2_UFCS_'
../../../include/cpp2util.h:838:53: note: expanded from macro 'CPP2_UFCS_'
#define CPP2_UFCS_(LAMBDADEFCAPT,QUALID,TEMPKW,...) \
^
mixed-bugfix-for-ufcs-non-local.cpp2:27:29: error: a lambda expression cannot appear in this context
[[nodiscard]] auto h() -> t<CPP2_UFCS_NONLOCAL(f)(o)> { return o; }// Fails on Clang 12 (lambda in unevaluated context).
^
../../../include/cpp2util.h:856:59: note: expanded from macro 'CPP2_UFCS_NONLOCAL'
../../../include/cpp2util.h:857:59: note: expanded from macro 'CPP2_UFCS_NONLOCAL'
#define CPP2_UFCS_NONLOCAL(...) CPP2_UFCS_(,(),,__VA_ARGS__)
^
../../../include/cpp2util.h:837:53: note: expanded from macro 'CPP2_UFCS_'
../../../include/cpp2util.h:838:53: note: expanded from macro 'CPP2_UFCS_'
#define CPP2_UFCS_(LAMBDADEFCAPT,QUALID,TEMPKW,...) \
^
mixed-bugfix-for-ufcs-non-local.cpp2:41:79: error: lambda expression in an unevaluated operand
inline CPP2_CONSTEXPR bool u::c = [](cpp2::in<std::type_identity_t<decltype(CPP2_UFCS_NONLOCAL(f)(o))>> x) mutable -> auto { return x; }(true);// Fails on Clang 12 (lambda in unevaluated context).
^
../../../include/cpp2util.h:856:59: note: expanded from macro 'CPP2_UFCS_NONLOCAL'
../../../include/cpp2util.h:857:59: note: expanded from macro 'CPP2_UFCS_NONLOCAL'
#define CPP2_UFCS_NONLOCAL(...) CPP2_UFCS_(,(),,__VA_ARGS__)
^
../../../include/cpp2util.h:837:53: note: expanded from macro 'CPP2_UFCS_'
../../../include/cpp2util.h:838:53: note: expanded from macro 'CPP2_UFCS_'
#define CPP2_UFCS_(LAMBDADEFCAPT,QUALID,TEMPKW,...) \
^
13 errors generated.
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ while_break_outer:
00 inner 01

do_continue_inner:
00 inner 01 02 inner 03 inner outer 10 inner 11 12 inner 13 inner outer 20 inner 21 22 inner 23 inner outer 30 inner 31 32 inner 33 inner outer
00 inner 01 02 inner outer 10 inner 11 12 inner outer 20 inner 21 22 inner outer
do_continue_outer:
00 inner 01 10 inner 11 20 inner 21 30 inner 31
00 inner 01 10 inner 11 20 inner 21
do_break_inner:
00 inner 01 outer 10 inner 11 outer 20 inner 21 outer 30 inner 31 outer
00 inner 01 outer 10 inner 11 outer 20 inner 21 outer
do_break_outer:
00 inner 01

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
pure2-bugfix-for-ufcs-noexcept.cpp2:5:26: error: lambda expression in an unevaluated operand
static_assert(noexcept(CPP2_UFCS(swap)(t(), t())));// Fails on Clang 12 (lambda in unevaluated context) and GCC 10 (static assertion failed)
^
../../../include/cpp2util.h:853:59: note: expanded from macro 'CPP2_UFCS'
../../../include/cpp2util.h:854:59: note: expanded from macro 'CPP2_UFCS'
#define CPP2_UFCS(...) CPP2_UFCS_(&,(),,__VA_ARGS__)
^
../../../include/cpp2util.h:837:53: note: expanded from macro 'CPP2_UFCS_'
../../../include/cpp2util.h:838:53: note: expanded from macro 'CPP2_UFCS_'
#define CPP2_UFCS_(LAMBDADEFCAPT,QUALID,TEMPKW,...) \
^
1 error generated.
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
pure2-bugfix-for-ufcs-sfinae.cpp2:1:78: error: lambda expression in an unevaluated operand
template<typename T> [[nodiscard]] auto f() -> std::type_identity_t<decltype(CPP2_UFCS_NONLOCAL(a)(T()))>;
^
../../../include/cpp2util.h:856:59: note: expanded from macro 'CPP2_UFCS_NONLOCAL'
../../../include/cpp2util.h:857:59: note: expanded from macro 'CPP2_UFCS_NONLOCAL'
#define CPP2_UFCS_NONLOCAL(...) CPP2_UFCS_(,(),,__VA_ARGS__)
^
../../../include/cpp2util.h:837:53: note: expanded from macro 'CPP2_UFCS_'
../../../include/cpp2util.h:838:53: note: expanded from macro 'CPP2_UFCS_'
#define CPP2_UFCS_(LAMBDADEFCAPT,QUALID,TEMPKW,...) \
^
pure2-bugfix-for-ufcs-sfinae.cpp2:1:78: error: lambda expression in an unevaluated operand
template<typename T> [[nodiscard]] auto f() -> std::type_identity_t<decltype(CPP2_UFCS_NONLOCAL(a)(T()))>{}// Fails on Clang 12 (lambda in unevaluated context).
^
../../../include/cpp2util.h:856:59: note: expanded from macro 'CPP2_UFCS_NONLOCAL'
../../../include/cpp2util.h:857:59: note: expanded from macro 'CPP2_UFCS_NONLOCAL'
#define CPP2_UFCS_NONLOCAL(...) CPP2_UFCS_(,(),,__VA_ARGS__)
^
../../../include/cpp2util.h:837:53: note: expanded from macro 'CPP2_UFCS_'
../../../include/cpp2util.h:838:53: note: expanded from macro 'CPP2_UFCS_'
#define CPP2_UFCS_(LAMBDADEFCAPT,QUALID,TEMPKW,...) \
^
2 errors generated.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Bounds safety violation: out of bounds access attempt detected
Bounds safety violation: out of bounds access attempt detected - attempted index 5, [min,max] range is [0,4]
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ while_break_outer:
00 inner 01

do_continue_inner:
00 inner 01 02 inner 03 inner outer 10 inner 11 12 inner 13 inner outer 20 inner 21 22 inner 23 inner outer 30 inner 31 32 inner 33 inner outer
00 inner 01 02 inner outer 10 inner 11 12 inner outer 20 inner 21 22 inner outer
do_continue_outer:
00 inner 01 10 inner 11 20 inner 21 30 inner 31
00 inner 01 10 inner 11 20 inner 21
do_break_inner:
00 inner 01 outer 10 inner 11 outer 20 inner 21 outer 30 inner 31 outer
00 inner 01 outer 10 inner 11 outer 20 inner 21 outer
do_break_outer:
00 inner 01

Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Bounds safety violation: out of bounds access attempt detected
Bounds safety violation: out of bounds access attempt detected - attempted index 5, [min,max] range is [0,4]
Loading

0 comments on commit b41f60e

Please sign in to comment.