Skip to content

Commit 1880055

Browse files
committed
refactor(cpp1): emit without else to silence warning
1 parent 855c47d commit 1880055

11 files changed

+14
-14
lines changed

regression-tests/test-results/mixed-inspect-templates.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ struct my_type {};
3737
else if (cpp2::is<std::array>(__expr)) { if constexpr( requires{"std::array";} ) if constexpr( std::is_convertible_v<CPP2_TYPEOF(("std::array")),std::string> ) return "std::array"; cpp2::Type.expects(false, "Statement of chosen alternative is invalid."); }
3838
else if (cpp2::is<std::variant>(__expr)) { if constexpr( requires{"std::variant";} ) if constexpr( std::is_convertible_v<CPP2_TYPEOF(("std::variant")),std::string> ) return "std::variant"; cpp2::Type.expects(false, "Statement of chosen alternative is invalid."); }
3939
else if (cpp2::is<my_type>(__expr)) { if constexpr( requires{"my_type";} ) if constexpr( std::is_convertible_v<CPP2_TYPEOF(("my_type")),std::string> ) return "my_type"; cpp2::Type.expects(false, "Statement of chosen alternative is invalid."); }
40-
else return "unknown"; }
40+
return "unknown"; }
4141
();
4242
}
4343

regression-tests/test-results/mixed-inspect-values-2.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ constexpr auto empty = [](auto&& x){
4141
std::cout << [&] () -> std::string { auto&& __expr = i;
4242
if (cpp2::is(__expr, (less_than(10)))) { if constexpr( requires{"i less than 10";} ) if constexpr( std::is_convertible_v<CPP2_TYPEOF(("i less than 10")),std::string> ) return "i less than 10"; cpp2::Type.expects(false, "Statement of chosen alternative is invalid."); }
4343
else if (cpp2::is(__expr, in(11, 20))) { if constexpr( requires{"i is between 11 and 20";} ) if constexpr( std::is_convertible_v<CPP2_TYPEOF(("i is between 11 and 20")),std::string> ) return "i is between 11 and 20"; cpp2::Type.expects(false, "Statement of chosen alternative is invalid."); }
44-
else return "i is out of our interest"; }
44+
return "i is out of our interest"; }
4545
() << std::endl;
4646

4747
if (cpp2::is(i, (less_than(20)))) {

regression-tests/test-results/mixed-inspect-values.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ auto test(auto const& x) -> void{
6262
else if (cpp2::is(__expr, std::move(forty_two))) { if constexpr( requires{"the answer";} ) if constexpr( std::is_convertible_v<CPP2_TYPEOF(("the answer")),std::string> ) return "the answer"; cpp2::Type.expects(false, "Statement of chosen alternative is invalid."); }
6363
else if (cpp2::is<int>(__expr)) { if constexpr( requires{"integer " + cpp2::to_string(x);} ) if constexpr( std::is_convertible_v<CPP2_TYPEOF(("integer " + cpp2::to_string(x))),std::string> ) return "integer " + cpp2::to_string(x); cpp2::Type.expects(false, "Statement of chosen alternative is invalid."); }
6464
else if (cpp2::is<std::string>(__expr)) { if constexpr( requires{cpp2::as<std::string>(x);} ) if constexpr( std::is_convertible_v<CPP2_TYPEOF((cpp2::as<std::string>(x))),std::string> ) return cpp2::as<std::string>(x); cpp2::Type.expects(false, "Statement of chosen alternative is invalid."); }
65-
else return "(no match)"; }
65+
return "(no match)"; }
6666
() << "\n";
6767
}
6868

regression-tests/test-results/mixed-inspect-with-typeof-of-template-arg-list.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ auto calc() {
3030
[[nodiscard]] auto fun(auto const& v) -> int{
3131
return [&] () -> int { auto&& __expr = v;
3232
if (cpp2::is<int>(__expr)) { if constexpr( requires{calc<1,2>();} ) if constexpr( std::is_convertible_v<CPP2_TYPEOF((calc<1,2>())),int> ) return calc<1,2>(); cpp2::Type.expects(false, "Statement of chosen alternative is invalid."); }
33-
else return 0; }
33+
return 0; }
3434
();
3535
}
3636

regression-tests/test-results/pure2-bugfix-for-runtime-invalid-alternative.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ auto main() -> int;
2424
auto f(auto const& x) -> void{
2525
cpp2::Default.expects([&] () -> cpp2::i32 { auto&& __expr = x;
2626
if (cpp2::is(__expr, 1)) { if constexpr( requires{[]() -> bool { return 2; }("");} ) if constexpr( std::is_convertible_v<CPP2_TYPEOF(([]() -> bool { return 2; }(""))),cpp2::i32> ) return []() -> bool { return 2; }(""); cpp2::Type.expects(false, "Statement of chosen alternative is invalid."); }
27-
else return 1; }
27+
return 1; }
2828
()==1, "");
2929
}
3030
auto main() -> int { f(1); }

regression-tests/test-results/pure2-inspect-expression-in-generic-function-multiple-types.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ auto test_generic(auto const& x, auto const& msg) -> void{
4747
<< [&] () -> std::string { auto&& __expr = x;
4848
if (cpp2::is<int>(__expr)) { if constexpr( requires{"integer " + std::to_string(cpp2::as<int>(x));} ) if constexpr( std::is_convertible_v<CPP2_TYPEOF(("integer " + std::to_string(cpp2::as<int>(x)))),std::string> ) return "integer " + std::to_string(cpp2::as<int>(x)); cpp2::Type.expects(false, "Statement of chosen alternative is invalid."); }
4949
else if (cpp2::is<std::string>(__expr)) { if constexpr( requires{'"' + cpp2::as<std::string>(x) + '"';} ) if constexpr( std::is_convertible_v<CPP2_TYPEOF(('"' + cpp2::as<std::string>(x) + '"')),std::string> ) return '"' + cpp2::as<std::string>(x) + '"'; cpp2::Type.expects(false, "Statement of chosen alternative is invalid."); }
50-
else return "not an int or string"; }
50+
return "not an int or string"; }
5151
()
5252
<< "\n";
5353
}

regression-tests/test-results/pure2-inspect-expression-with-as-in-generic-function.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ auto print_an_int(auto const& x) -> void{
3333
<< " value is "
3434
<< [&] () -> std::string { auto&& __expr = x;
3535
if (cpp2::is<int>(__expr)) { if constexpr( requires{std::to_string(cpp2::as<int>(x));} ) if constexpr( std::is_convertible_v<CPP2_TYPEOF((std::to_string(cpp2::as<int>(x)))),std::string> ) return std::to_string(cpp2::as<int>(x)); cpp2::Type.expects(false, "Statement of chosen alternative is invalid."); }
36-
else return "not an int"; }
36+
return "not an int"; }
3737
()
3838
<< "\n";
3939
}

regression-tests/test-results/pure2-inspect-fallback-with-variant-any-optional.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ auto test_generic(auto const& x, auto const& msg) -> void{
4343
else if (cpp2::is<std::variant<int,std::string>>(__expr)) { if constexpr( requires{" matches std::variant<int, std::string>";} ) if constexpr( std::is_convertible_v<CPP2_TYPEOF((" matches std::variant<int, std::string>")),std::string> ) return " matches std::variant<int, std::string>"; cpp2::Type.expects(false, "Statement of chosen alternative is invalid."); }
4444
else if (cpp2::is<std::any>(__expr)) { if constexpr( requires{" matches std::any";} ) if constexpr( std::is_convertible_v<CPP2_TYPEOF((" matches std::any")),std::string> ) return " matches std::any"; cpp2::Type.expects(false, "Statement of chosen alternative is invalid."); }
4545
else if (cpp2::is<std::optional<std::string>>(__expr)) { if constexpr( requires{" matches std::optional<std::string>";} ) if constexpr( std::is_convertible_v<CPP2_TYPEOF((" matches std::optional<std::string>")),std::string> ) return " matches std::optional<std::string>"; cpp2::Type.expects(false, "Statement of chosen alternative is invalid."); }
46-
else return " no match"; }
46+
return " no match"; }
4747
()
4848
<< "\n";
4949
}

regression-tests/test-results/pure2-inspect-generic-void-empty-with-variant-any-optional.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ auto test_generic(auto const& x, auto const& msg) -> void{
4444
<< "\n" << msg << "\n ..."
4545
<< [&] () -> std::string { auto&& __expr = x;
4646
if (cpp2::is<void>(__expr)) { if constexpr( requires{" VOYDE AND EMPTIE";} ) if constexpr( std::is_convertible_v<CPP2_TYPEOF((" VOYDE AND EMPTIE")),std::string> ) return " VOYDE AND EMPTIE"; cpp2::Type.expects(false, "Statement of chosen alternative is invalid."); }
47-
else return " no match"; }
47+
return " no match"; }
4848
()
4949
<< "\n";
5050
}

regression-tests/test-results/pure2-type-safety-2-with-inspect-expression.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ auto test_generic(auto const& x, auto const& msg) -> void{
4646
<< " value is "
4747
<< [&] () -> std::string { auto&& __expr = x;
4848
if (cpp2::is<int>(__expr)) { if constexpr( requires{std::to_string(cpp2::as<int>(x));} ) if constexpr( std::is_convertible_v<CPP2_TYPEOF((std::to_string(cpp2::as<int>(x)))),std::string> ) return std::to_string(cpp2::as<int>(x)); cpp2::Type.expects(false, "Statement of chosen alternative is invalid."); }
49-
else return "not an int"; }
49+
return "not an int"; }
5050
()
5151
<< "\n";
5252
}

source/cppfront.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1911,10 +1911,6 @@ class cppfront
19111911
for (auto first = true; auto&& alt : n.alternatives)
19121912
{
19131913
assert(alt && alt->is_as_keyword);
1914-
if (!first) {
1915-
printer.print_cpp2("else ", alt->position());
1916-
}
1917-
first = false;
19181914

19191915
auto id = std::string{};
19201916
printer.emit_to_string(&id);
@@ -1972,6 +1968,10 @@ class cppfront
19721968
}
19731969
}
19741970
else {
1971+
if (!first) {
1972+
printer.print_cpp2("else ", alt->position());
1973+
}
1974+
first = false;
19751975
printer.print_cpp2("if " + constexpr_qualifier, alt->position());
19761976
if (alt->type_id) {
19771977
printer.print_cpp2("(cpp2::is<" + id + ">(__expr)) ", alt->position());

0 commit comments

Comments
 (0)