Skip to content

Commit 1e6d740

Browse files
authored
fix(cpp1): flank == with spaces to preserve meaning (#617)
* test: add `pure2-bugfix-for-max-munch` * fix(cpp1): flank `==` with spaces to preserve meaning * test: refactor to prevent warnings * refactor: regenerate `reflect.h` and `regression-tests`
1 parent 8f8abde commit 1e6d740

17 files changed

+74
-45
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
v: <T> == 0;
2+
main: () = _ = v<i32> == v<i64>;

regression-tests/test-results/clang-18/pure2-bugfix-for-max-munch.cpp.execution

Whitespace-only changes.

regression-tests/test-results/clang-18/pure2-bugfix-for-max-munch.cpp.output

Whitespace-only changes.

regression-tests/test-results/mixed-bugfix-for-literal-as-nttp.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ auto main() -> int;
2020

2121
#line 3 "mixed-bugfix-for-literal-as-nttp.cpp2"
2222
auto main() -> int{
23-
cpp2::Default.expects(cpp2::as_<cpp2::i32, 10>()==10, "");
24-
cpp2::Default.expects(cpp2::as_<cpp2::i32, 10LL>()==10, "");
25-
cpp2::Default.expects(cpp2::as_<std::chrono::seconds>(10s)==10s, "");
23+
cpp2::Default.expects(cpp2::as_<cpp2::i32, 10>() == 10, "");
24+
cpp2::Default.expects(cpp2::as_<cpp2::i32, 10LL>() == 10, "");
25+
cpp2::Default.expects(cpp2::as_<std::chrono::seconds>(10s) == 10s, "");
2626
}
2727

regression-tests/test-results/mixed-captures-in-expressions-and-postconditions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ auto insert_at(cpp2::in<int> where, cpp2::in<int> val) -> void
4646
#line 22 "mixed-captures-in-expressions-and-postconditions.cpp2"
4747
{
4848
cpp2::Default.expects(cpp2::cmp_less_eq(0,where) && cpp2::cmp_less_eq(where,CPP2_UFCS_0(ssize, vec)), "");
49-
auto post_21_5 = cpp2::finally_success([_0 = CPP2_UFCS_0(ssize, vec)]{cpp2::Default.expects(CPP2_UFCS_0(ssize, vec)==_0 + 1, "");} );
49+
auto post_21_5 = cpp2::finally_success([_0 = CPP2_UFCS_0(ssize, vec)]{cpp2::Default.expects(CPP2_UFCS_0(ssize, vec) == _0 + 1, "");} );
5050
#line 23 "mixed-captures-in-expressions-and-postconditions.cpp2"
5151
static_cast<void>(CPP2_UFCS(insert, vec, CPP2_UFCS_0(begin, vec) + where, val));
5252
}

regression-tests/test-results/mixed-initialization-safety-3.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,5 +62,5 @@ auto fill(
6262
auto print_decorated(auto const& x) -> void { std::cout << ">> [" << x << "]\n"; }
6363

6464
#line 30 "mixed-initialization-safety-3.cpp2"
65-
[[nodiscard]] auto flip_a_coin() -> bool { return std::mt19937()() % 2==0; }
65+
[[nodiscard]] auto flip_a_coin() -> bool { return std::mt19937()() % 2 == 0; }
6666

regression-tests/test-results/mixed-parameter-passing-with-forward.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ requires (std::is_same_v<CPP2_TYPEOF(e), std::string>)
6868

6969
copy_from(z);
7070

71-
if (std::time(nullptr) % 2==0) {
71+
if (std::time(nullptr) % 2 == 0) {
7272
copy_from(std::move(z));
7373
}
7474

regression-tests/test-results/mixed-parameter-passing.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ auto parameter_styles(
6060

6161
copy_from(z);
6262

63-
if (std::time(nullptr) % 2==0) {
63+
if (std::time(nullptr) % 2 == 0) {
6464
copy_from(std::move(z));
6565
}
6666

regression-tests/test-results/mixed-postexpression-with-capture.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ auto insert_at(cpp2::in<int> where, cpp2::in<int> val) -> void
4141
#line 17 "mixed-postexpression-with-capture.cpp2"
4242
{
4343
cpp2::Default.expects(cpp2::cmp_less_eq(0,where) && cpp2::cmp_less_eq(where,CPP2_UFCS_0(ssize, vec)), "");
44-
auto post_16_5 = cpp2::finally_success([_0 = CPP2_UFCS_0(size, vec)]{cpp2::Default.expects(CPP2_UFCS_0(size, vec)==_0 + 1, "");} );
44+
auto post_16_5 = cpp2::finally_success([_0 = CPP2_UFCS_0(size, vec)]{cpp2::Default.expects(CPP2_UFCS_0(size, vec) == _0 + 1, "");} );
4545
#line 18 "mixed-postexpression-with-capture.cpp2"
4646
CPP2_UFCS(push_back, vec, val);
4747
}

regression-tests/test-results/pure2-break-continue.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ auto while_continue_inner() -> void
8282
#line 25 "pure2-break-continue.cpp2"
8383
{
8484
std::cout << i << j << " ";
85-
if (j==1) {
85+
if (j == 1) {
8686
goto CONTINUE_25_9;
8787
}
8888
std::cout << "inner ";
@@ -101,7 +101,7 @@ auto while_continue_outer() -> void
101101
auto j {0};
102102
for( ; cpp2::cmp_less(j,3); ++j ) {
103103
std::cout << i << j << " ";
104-
if (j==1) {
104+
if (j == 1) {
105105
goto CONTINUE_39_5;
106106
}
107107
std::cout << "inner ";
@@ -120,7 +120,7 @@ auto while_break_inner() -> void
120120
#line 57 "pure2-break-continue.cpp2"
121121
{
122122
std::cout << i << j << " ";
123-
if (j==1) {
123+
if (j == 1) {
124124
goto BREAK_57_9;
125125
}
126126
std::cout << "inner ";
@@ -139,7 +139,7 @@ auto while_break_outer() -> void
139139
auto j {0};
140140
for( ; cpp2::cmp_less(j,3); ++j ) {
141141
std::cout << i << j << " ";
142-
if (j==1) {
142+
if (j == 1) {
143143
goto BREAK_71_5;
144144
}
145145
std::cout << "inner ";
@@ -158,7 +158,7 @@ auto do_continue_inner() -> void
158158
#line 89 "pure2-break-continue.cpp2"
159159
{
160160
std::cout << i << j << " ";
161-
if (j==1) {
161+
if (j == 1) {
162162
goto CONTINUE_89_9;
163163
}
164164
std::cout << "inner ";
@@ -183,7 +183,7 @@ auto do_continue_outer() -> void
183183
auto j {0};
184184
do {
185185
std::cout << i << j << " ";
186-
if (j==1) {
186+
if (j == 1) {
187187
goto CONTINUE_106_5;
188188
}
189189
std::cout << "inner ";
@@ -208,7 +208,7 @@ auto do_break_inner() -> void
208208
#line 127 "pure2-break-continue.cpp2"
209209
{
210210
std::cout << i << j << " ";
211-
if (j==1) {
211+
if (j == 1) {
212212
goto BREAK_127_9;
213213
}
214214
std::cout << "inner ";
@@ -233,7 +233,7 @@ auto do_break_outer() -> void
233233
auto j {0};
234234
do {
235235
std::cout << i << j << " ";
236-
if (j==1) {
236+
if (j == 1) {
237237
goto BREAK_144_5;
238238
}
239239
std::cout << "inner ";
@@ -259,7 +259,7 @@ auto for_continue_inner() -> void
259259
#line 166 "pure2-break-continue.cpp2"
260260
{
261261
std::cout << i << j << " ";
262-
if (j==1) {
262+
if (j == 1) {
263263
goto CONTINUE_166_9;
264264
}
265265
std::cout << "inner ";
@@ -280,7 +280,7 @@ auto for_continue_outer() -> void
280280
std::vector vj {0, 1, 2};
281281
for ( auto const& j : vj ) {
282282
std::cout << i << j << " ";
283-
if (j==1) {
283+
if (j == 1) {
284284
goto CONTINUE_182_5;
285285
}
286286
std::cout << "inner ";
@@ -301,7 +301,7 @@ auto for_break_inner() -> void
301301
#line 202 "pure2-break-continue.cpp2"
302302
{
303303
std::cout << i << j << " ";
304-
if (j==1) {
304+
if (j == 1) {
305305
goto BREAK_202_9;
306306
}
307307
std::cout << "inner ";
@@ -322,7 +322,7 @@ auto for_break_outer() -> void
322322
std::vector vj {0, 1, 2};
323323
for ( auto const& j : vj ) {
324324
std::cout << i << j << " ";
325-
if (j==1) {
325+
if (j == 1) {
326326
goto BREAK_218_5;
327327
}
328328
std::cout << "inner ";

regression-tests/test-results/pure2-bugfix-for-assign-expression-list.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ auto main() -> int{
2121
using vec = std::vector<int>;
2222
vec v {0};
2323
v = { };
24-
cpp2::Default.expects(v==vec{}, "");
24+
cpp2::Default.expects(v == vec{}, "");
2525
v = { 1 };
26-
cpp2::Default.expects(v==vec{1}, "");
26+
cpp2::Default.expects(v == vec{1}, "");
2727
v = { 2, 3 };
28-
cpp2::Default.expects(std::move(v)==vec{2, 3}, "");
28+
cpp2::Default.expects(std::move(v) == vec{2, 3}, "");
2929
}
3030

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
#define CPP2_USE_MODULES Yes
3+
4+
//=== Cpp2 type declarations ====================================================
5+
6+
7+
#include "cpp2util.h"
8+
9+
10+
11+
//=== Cpp2 type definitions and function declarations ===========================
12+
13+
#line 1 "pure2-bugfix-for-max-munch.cpp2"
14+
template<typename T> auto const& v = 0;
15+
auto main() -> int;
16+
17+
18+
//=== Cpp2 function definitions =================================================
19+
20+
21+
#line 2 "pure2-bugfix-for-max-munch.cpp2"
22+
auto main() -> int { static_cast<void>(v<cpp2::i32> == v<cpp2::i64>); }
23+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
pure2-bugfix-for-max-munch.cpp2... ok (all Cpp2, passes safety checks)
2+

regression-tests/test-results/pure2-initialization-safety-with-else-if.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ auto main(int const argc_, char** argv_) -> int{
2727
auto c {3};
2828
auto d {4};
2929

30-
if (CPP2_UFCS_0(size, args)==3) {
30+
if (CPP2_UFCS_0(size, args) == 3) {
3131
p.construct(&a);
3232
}else {if (true) {
33-
if (CPP2_UFCS_0(size, args)==2) {
33+
if (CPP2_UFCS_0(size, args) == 2) {
3434
p.construct(&c);
3535
}else {if (cpp2::cmp_greater(std::move(b),0)) {
3636
p.construct(&a);

regression-tests/test-results/pure2-look-up-parameter-across-unnamed-function.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ struct f__ret { int ri; };
3333
[[nodiscard]] auto f() -> f__ret{
3434
int ri {0};
3535
#line 3 "pure2-look-up-parameter-across-unnamed-function.cpp2"
36-
auto pred {[](auto const& e) -> bool{return e==1; }};
36+
auto pred {[](auto const& e) -> bool{return e == 1; }};
3737
ri = 42;
3838
return { std::move(ri) }; // "return;" is implicit"
3939
}
@@ -42,7 +42,7 @@ struct f__ret { int ri; };
4242
cpp2::deferred_init<int> ri;
4343
#line 9 "pure2-look-up-parameter-across-unnamed-function.cpp2"
4444
ri.construct(0);
45-
auto pred {[](auto const& e) -> bool{return e==1; }};
45+
auto pred {[](auto const& e) -> bool{return e == 1; }};
4646
ri.value() = 42;
4747
return { std::move(ri.value()) };
4848
}

source/cppfront.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3299,7 +3299,9 @@ class cppfront
32993299
switch (op.type()) {
33003300
break;case lexeme::EqualComparison:
33013301
case lexeme::NotEqualComparison:
3302+
printer.print_cpp2( " ", n.position() );
33023303
emit(op);
3304+
printer.print_cpp2( " ", n.position() );
33033305
break;default:
33043306
printer.print_cpp2( ",", n.position() );
33053307
}

source/reflect.h

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -733,7 +733,7 @@ namespace meta {
733733
auto lines {&CPP2_UFCS_0(back, generated_lines)};
734734

735735
auto add_line {[&, _1 = lines](cpp2::in<std::string_view> s) -> void{
736-
(void) CPP2_UFCS(emplace_back, (*cpp2::assert_not_null(_1)), s, source_line::category::cpp2);
736+
static_cast<void>(CPP2_UFCS(emplace_back, (*cpp2::assert_not_null(_1)), s, source_line::category::cpp2));
737737
}};
738738
{
739739
auto newline_pos = CPP2_UFCS(find, source, '\n');
@@ -743,9 +743,9 @@ auto newline_pos = CPP2_UFCS(find, source, '\n');
743743

744744
#line 72 "reflect.h2"
745745
if ( cpp2::cmp_greater(CPP2_UFCS_0(ssize, source),1)
746-
&& newline_pos!=source.npos)
746+
&& newline_pos != source.npos)
747747
{
748-
while( newline_pos!=std::string_view::npos )
748+
while( newline_pos != std::string_view::npos )
749749
{
750750
add_line(CPP2_UFCS(substr, source, 0, newline_pos));
751751
CPP2_UFCS(remove_prefix, source, newline_pos + 1);
@@ -762,11 +762,11 @@ auto newline_pos = CPP2_UFCS(find, source, '\n');
762762
// Now lex this source fragment to generate
763763
// a single grammar_map entry, whose .second
764764
// is the vector of tokens
765-
(void) CPP2_UFCS(emplace_back, generated_lexers, *cpp2::assert_not_null(errors));
765+
static_cast<void>(CPP2_UFCS(emplace_back, generated_lexers, *cpp2::assert_not_null(errors)));
766766
auto tokens {&CPP2_UFCS_0(back, generated_lexers)};
767767
CPP2_UFCS(lex, (*cpp2::assert_not_null(tokens)), *cpp2::assert_not_null(std::move(lines)), true);
768768

769-
cpp2::Default.expects(std::ssize(CPP2_UFCS_0(get_map, (*cpp2::assert_not_null(tokens))))==1, "");
769+
cpp2::Default.expects(std::ssize(CPP2_UFCS_0(get_map, (*cpp2::assert_not_null(tokens)))) == 1, "");
770770

771771
// Now parse this single declaration from
772772
// the lexed tokens
@@ -799,7 +799,7 @@ auto newline_pos = CPP2_UFCS(find, source, '\n');
799799
if (!(CPP2_UFCS_0(empty, meta_function_name))) {
800800
message = "while applying @" + meta_function_name + " - " + message;
801801
}
802-
(void) CPP2_UFCS(emplace_back, (*cpp2::assert_not_null(errors)), position(), std::move(message));
802+
static_cast<void>(CPP2_UFCS(emplace_back, (*cpp2::assert_not_null(errors)), position(), std::move(message)));
803803
}
804804

805805
compiler_services::~compiler_services() noexcept{}
@@ -849,9 +849,9 @@ declaration_base::declaration_base(declaration_base const& that)
849849
[[nodiscard]] auto declaration::is_private() const -> bool { return CPP2_UFCS_0(is_private, (*cpp2::assert_not_null(n))); }
850850
[[nodiscard]] auto declaration::is_default_access() const -> bool { return CPP2_UFCS_0(is_default_access, (*cpp2::assert_not_null(n))); }
851851

852-
auto declaration::default_to_public() -> void { (void) CPP2_UFCS_0(make_public, (*cpp2::assert_not_null(n))); }
853-
auto declaration::default_to_protected() -> void { (void) CPP2_UFCS_0(make_protected, (*cpp2::assert_not_null(n))); }
854-
auto declaration::default_to_private() -> void { (void) CPP2_UFCS_0(make_private, (*cpp2::assert_not_null(n))); }
852+
auto declaration::default_to_public() -> void { static_cast<void>(CPP2_UFCS_0(make_public, (*cpp2::assert_not_null(n)))); }
853+
auto declaration::default_to_protected() -> void { static_cast<void>(CPP2_UFCS_0(make_protected, (*cpp2::assert_not_null(n)))); }
854+
auto declaration::default_to_private() -> void { static_cast<void>(CPP2_UFCS_0(make_private, (*cpp2::assert_not_null(n)))); }
855855

856856
[[nodiscard]] auto declaration::make_public() -> bool { return CPP2_UFCS_0(make_public, (*cpp2::assert_not_null(n))); }
857857
[[nodiscard]] auto declaration::make_protected() -> bool { return CPP2_UFCS_0(make_protected, (*cpp2::assert_not_null(n))); }
@@ -940,7 +940,7 @@ declaration::declaration(declaration const& that)
940940

941941
[[nodiscard]] auto function_declaration::is_binary_comparison_function() const -> bool { return CPP2_UFCS_0(is_binary_comparison_function, (*cpp2::assert_not_null(n))); }
942942

943-
auto function_declaration::default_to_virtual() -> void { (void) CPP2_UFCS_0(make_function_virtual, (*cpp2::assert_not_null(n))); }
943+
auto function_declaration::default_to_virtual() -> void { static_cast<void>(CPP2_UFCS_0(make_function_virtual, (*cpp2::assert_not_null(n)))); }
944944

945945
[[nodiscard]] auto function_declaration::make_virtual() -> bool { return CPP2_UFCS_0(make_function_virtual, (*cpp2::assert_not_null(n))); }
946946

@@ -1002,7 +1002,7 @@ declaration::declaration(declaration const& that)
10021002
{
10031003
std::vector<function_declaration> ret {};
10041004
for ( auto const& d : CPP2_UFCS(get_type_scope_declarations, (*cpp2::assert_not_null(n)), declaration_node::functions) ) {
1005-
(void) CPP2_UFCS(emplace_back, ret, d, (*this));
1005+
static_cast<void>(CPP2_UFCS(emplace_back, ret, d, (*this)));
10061006
}
10071007
return ret;
10081008
}
@@ -1012,7 +1012,7 @@ declaration::declaration(declaration const& that)
10121012
{
10131013
std::vector<object_declaration> ret {};
10141014
for ( auto const& d : CPP2_UFCS(get_type_scope_declarations, (*cpp2::assert_not_null(n)), declaration_node::objects) ) {
1015-
(void) CPP2_UFCS(emplace_back, ret, d, (*this));
1015+
static_cast<void>(CPP2_UFCS(emplace_back, ret, d, (*this)));
10161016
}
10171017
return ret;
10181018
}
@@ -1022,7 +1022,7 @@ declaration::declaration(declaration const& that)
10221022
{
10231023
std::vector<type_declaration> ret {};
10241024
for ( auto const& d : CPP2_UFCS(get_type_scope_declarations, (*cpp2::assert_not_null(n)), declaration_node::types) ) {
1025-
(void) CPP2_UFCS(emplace_back, ret, d, (*this));
1025+
static_cast<void>(CPP2_UFCS(emplace_back, ret, d, (*this)));
10261026
}
10271027
return ret;
10281028
}
@@ -1032,7 +1032,7 @@ declaration::declaration(declaration const& that)
10321032
{
10331033
std::vector<declaration> ret {};
10341034
for ( auto const& d : CPP2_UFCS(get_type_scope_declarations, (*cpp2::assert_not_null(n)), declaration_node::all) ) {
1035-
(void) CPP2_UFCS(emplace_back, ret, d, (*this));
1035+
static_cast<void>(CPP2_UFCS(emplace_back, ret, d, (*this)));
10361036
}
10371037
return ret;
10381038
}
@@ -1048,9 +1048,9 @@ declaration::declaration(declaration const& that)
10481048
#line 423 "reflect.h2"
10491049
auto declared {CPP2_UFCS_0(find_declared_value_set_functions, (*cpp2::assert_not_null(n)))};
10501050
out_this_in_that.construct(declared.out_this_in_that != nullptr);
1051-
out_this_move_that.construct(declared.out_this_move_that!=nullptr);
1052-
inout_this_in_that.construct(declared.inout_this_in_that!=nullptr);
1053-
inout_this_move_that.construct(std::move(declared).inout_this_move_that!=nullptr);
1051+
out_this_move_that.construct(declared.out_this_move_that != nullptr);
1052+
inout_this_in_that.construct(declared.inout_this_in_that != nullptr);
1053+
inout_this_move_that.construct(std::move(declared).inout_this_move_that != nullptr);
10541054
return { std::move(out_this_in_that.value()), std::move(out_this_move_that.value()), std::move(inout_this_in_that.value()), std::move(inout_this_move_that.value()) }; }
10551055

10561056
[[nodiscard]] auto type_declaration::add_member(cpp2::in<std::string_view> source) ->
@@ -1142,7 +1142,7 @@ auto ordered_impl(
11421142
if (CPP2_UFCS(has_name, mf, "operator<=>")) {
11431143
has_spaceship = true;
11441144
auto return_name {CPP2_UFCS_0(unnamed_return_type, mf)};
1145-
if (CPP2_UFCS(find, return_name, ordering)==return_name.npos)
1145+
if (CPP2_UFCS(find, return_name, ordering) == return_name.npos)
11461146
{
11471147
CPP2_UFCS(error, mf, "operator<=> must return std::" + cpp2::as_<std::string>(ordering));
11481148
}

0 commit comments

Comments
 (0)