Skip to content

Commit b9a0b21

Browse files
committed
Compile Cppfront cleanly using MSVC /W4, GCC /Wall, Clang /Wall
Cppfront now compiles cleanly using these command lines: - `cl cppfront.cpp -std:c++20 -EHsc -W4` - `g++-10 -std=c++20 cppfront.cpp -Wall` - `clang++-12 -std=c++20 cppfront.cpp -Wall` This exposed (and this commit fixes) one bug: Cppfront should reject `move` and `forward` only if preceded by `std::` Note: I don't currently see a benefit to trying to compile cleanly under -Wextra: - GCC-10 -Wextra generates 3 -Wmissing-field-initializer that seem spurious, and 1 -Wimplicit-fallthrough that is intentional and commented (I looked again and if there's a bug I'm not seeing it) - Clang-12 -Wextra generates two -Wmissing-field-initializer warnings that don't seem useful
1 parent 29f072e commit b9a0b21

File tree

6 files changed

+45
-49
lines changed

6 files changed

+45
-49
lines changed

source/common.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@
1111
// THE SOFTWARE.
1212

1313

14+
#ifdef _MSC_VER
15+
#pragma warning(disable: 4456)
16+
#endif
17+
//#include "../include/cpp2util.h"
18+
19+
1420
//===========================================================================
1521
// Common types
1622
//===========================================================================
@@ -396,7 +402,7 @@ class cmdline_processor
396402
}
397403
print(" -");
398404
auto n = flag.name.substr(0, flag.unique_prefix);
399-
if (flag.unique_prefix < flag.name.length()) {
405+
if (flag.unique_prefix < std::ssize(flag.name)) {
400406
n += "[";
401407
n += flag.name.substr(flag.unique_prefix);
402408
n += "]";

source/cppfront.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ class positional_printer
190190
// Update curr_pos by finding how many line breaks s contained,
191191
// and where the last one was which determines our current colno
192192
auto last_newline = std::string::npos; // the last newline we found in the string
193-
auto newline_pos = 0; // the current newline we found in the string
193+
auto newline_pos = std::size_t(0); // the current newline we found in the string
194194
while ((newline_pos = s.find('\n', newline_pos)) != std::string::npos)
195195
{
196196
// For each line break we find, reset pad and inc current lineno
@@ -1638,7 +1638,7 @@ class cppfront
16381638
}
16391639
++mynum;
16401640
}
1641-
assert (mynum < n.cap_grp->size() && "could not find this postfix-expression in capture group");
1641+
assert (mynum < std::ssize(*n.cap_grp) && "could not find this postfix-expression in capture group");
16421642
// And then emit that capture number
16431643
captured_part += "_" + std::to_string(mynum);
16441644
}
@@ -1714,7 +1714,6 @@ class cppfront
17141714
auto prefix = std::vector<text_with_pos>{};
17151715
auto suffix = std::vector<text_with_pos>{};
17161716

1717-
auto emitted_n = false;
17181717
auto last_was_prefixed = false;
17191718
auto saw_dollar = false;
17201719

source/lex.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ auto lex_line(
295295
//
296296
auto peek = [&](int num) { return (i+num < std::ssize(line)) ? line[i+num] : '\0'; };
297297

298-
auto store = [&](int16_t num, lexeme type)
298+
auto store = [&](auto num, lexeme type)
299299
{
300300
tokens.push_back({
301301
&line[i],
@@ -445,7 +445,7 @@ auto lex_line(
445445
if (std::regex_search(&line[i], m, keys)) {
446446
assert (m.position(0) == 0);
447447
// If we matched and what's next is EOL or a non-identifier char, we matched!
448-
if (i+m[0].length() == line.length() || // EOL
448+
if (i+m[0].length() == std::ssize(line) || // EOL
449449
!is_identifier_continue(line[i+m[0].length()]) // non-identifier char
450450
)
451451
{

source/load.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -302,8 +302,6 @@ auto process_cpp2_line(
302302
std::string const& line,
303303
bool& in_comment,
304304
std::vector<int>& brace_depth,
305-
bool& found_semi,
306-
bool& found_openbrace,
307305
lineno_t lineno,
308306
std::vector<error>& errors
309307
)
@@ -481,15 +479,11 @@ class source
481479
}
482480

483481
// Find the end of the definition:
484-
auto found_semi = false;
485-
auto found_openbrace = false;
486482
while (
487483
!process_cpp2_line(
488484
lines.back().text,
489485
in_comment,
490486
brace_depth,
491-
found_semi,
492-
found_openbrace,
493487
std::ssize(lines)-1,
494488
errors
495489
)

source/parse.h

Lines changed: 28 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -882,7 +882,7 @@ struct declaration_node
882882

883883
token const* pointer_declarator = nullptr;
884884

885-
enum active { function, object };
885+
enum active : std::uint8_t { function, object };
886886
std::variant<
887887
std::unique_ptr<function_type_node>,
888888
std::unique_ptr<type_id_node>
@@ -1267,7 +1267,7 @@ class parser
12671267
errors.emplace_back( curr().position(), m );
12681268
}
12691269

1270-
auto error(std::string const& msg, bool include_curr_token = true) const -> void
1270+
auto error(std::string const& msg, bool = true) const -> void
12711271
{
12721272
error(msg.c_str());
12731273
}
@@ -1638,7 +1638,7 @@ class parser
16381638
}
16391639
else {
16401640
return binary_expression<relational_expression_node> (
1641-
[](token const& t){ return false; },
1641+
[](token const&){ return false; },
16421642
[this]{ return compare_expression(); }
16431643
);
16441644
}
@@ -1950,7 +1950,7 @@ class parser
19501950
return {};
19511951
}
19521952
assert (term.id->identifier);
1953-
if (first_time_through_loop && term.scope_op->type() == lexeme::Scope) {
1953+
if (first_time_through_loop && first_uid_was_std && term.scope_op->type() == lexeme::Scope) {
19541954
if (*term.id->identifier == "move") {
19551955
error("std::move is not needed in Cpp2 - use 'move' parameters/arguments instead", false);
19561956
return {};
@@ -2839,7 +2839,7 @@ class parser
28392839
//G : type-id-opt = statement
28402840
//G : type-id
28412841
//G
2842-
auto unnamed_declaration(source_position pos, bool semicolon_required = true, bool captures_allowed = false) -> std::unique_ptr<declaration_node>
2842+
auto unnamed_declaration(source_position start, bool semicolon_required = true, bool captures_allowed = false) -> std::unique_ptr<declaration_node>
28432843
{
28442844
auto deduced_type = false;
28452845

@@ -2850,16 +2850,13 @@ class parser
28502850
next();
28512851

28522852
auto n = std::make_unique<declaration_node>();
2853-
n->pos = pos;
2853+
n->pos = start;
28542854
auto guard =
28552855
captures_allowed
28562856
? make_unique<capture_groups_stack_guard>(this, &n->captures)
28572857
: std::unique_ptr<capture_groups_stack_guard>()
28582858
;
28592859

2860-
// Remember current position, because we need to look ahead
2861-
auto start_pos = pos;
2862-
28632860
// Next is an an optional type
28642861

28652862
// It could be a function type, declaring a function
@@ -3043,7 +3040,7 @@ class parse_tree_printer : printing_visitor
30433040
o << pre(indent) << n.to_string() << "\n";
30443041
}
30453042

3046-
auto start(expression_node const& n, int indent) -> void
3043+
auto start(expression_node const&, int indent) -> void
30473044
{
30483045
o << pre(indent) << "expression\n";
30493046
// If we are in an expression-list
@@ -3067,7 +3064,7 @@ class parse_tree_printer : printing_visitor
30673064
o << pre(indent) << "expression-list\n";
30683065
}
30693066

3070-
auto end(expression_list_node const& n, int indent) -> void
3067+
auto end(expression_list_node const& n, int) -> void
30713068
{
30723069
// If we're ending an expression list node, our pointer should be
30733070
// pointing to one past the end of the expressions
@@ -3081,58 +3078,58 @@ class parse_tree_printer : printing_visitor
30813078
current_expression_list_term.pop_back();
30823079
}
30833080

3084-
auto start(primary_expression_node const& n, int indent) -> void
3081+
auto start(primary_expression_node const&, int indent) -> void
30853082
{
30863083
o << pre(indent) << "primary-expression\n";
30873084
}
30883085

3089-
auto start(prefix_expression_node const& n, int indent) -> void
3086+
auto start(prefix_expression_node const&, int indent) -> void
30903087
{
30913088
o << pre(indent) << "prefix-expression\n";
30923089
}
30933090

30943091
template<String Name, typename Term>
3095-
auto start(binary_expression_node<Name, Term> const& n, int indent) -> void
3092+
auto start(binary_expression_node<Name, Term> const&, int indent) -> void
30963093
{
30973094
o << pre(indent) << Name.value << "-expression\n";
30983095
}
30993096

3100-
auto start(expression_statement_node const& n, int indent) -> void
3097+
auto start(expression_statement_node const&, int indent) -> void
31013098
{
31023099
o << pre(indent) << "expression-statement\n";
31033100
}
31043101

3105-
auto start(postfix_expression_node const& n, int indent) -> void
3102+
auto start(postfix_expression_node const&, int indent) -> void
31063103
{
31073104
o << pre(indent) << "postfix-expression\n";
31083105
}
31093106

3110-
auto start(unqualified_id_node const& n, int indent) -> void
3107+
auto start(unqualified_id_node const&, int indent) -> void
31113108
{
31123109
o << pre(indent) << "unqualified-id\n";
31133110
}
31143111

3115-
auto start(qualified_id_node const& n, int indent) -> void
3112+
auto start(qualified_id_node const&, int indent) -> void
31163113
{
31173114
o << pre(indent) << "qualified-id\n";
31183115
}
31193116

3120-
auto start(type_id_node const& n, int indent) -> void
3117+
auto start(type_id_node const&, int indent) -> void
31213118
{
31223119
o << pre(indent) << "type-id\n";
31233120
}
31243121

3125-
auto start(id_expression_node const& n, int indent) -> void
3122+
auto start(id_expression_node const&, int indent) -> void
31263123
{
31273124
o << pre(indent) << "id-expression\n";
31283125
}
31293126

3130-
auto start(statement_node const& n, int indent) -> void
3127+
auto start(statement_node const&, int indent) -> void
31313128
{
31323129
o << pre(indent) << "statement\n";
31333130
}
31343131

3135-
auto start(compound_statement_node const& n, int indent) -> void
3132+
auto start(compound_statement_node const&, int indent) -> void
31363133
{
31373134
o << pre(indent) << "compound-statement\n";
31383135
}
@@ -3143,7 +3140,7 @@ class parse_tree_printer : printing_visitor
31433140
o << pre(indent+1) << "is_constexpr: " << as<std::string>(n.is_constexpr) << "\n";
31443141
}
31453142

3146-
auto start(alternative_node const& n, int indent) -> void
3143+
auto start(alternative_node const&, int indent) -> void
31473144
{
31483145
o << pre(indent) << "alternative\n";
31493146
}
@@ -3154,7 +3151,7 @@ class parse_tree_printer : printing_visitor
31543151
o << pre(indent+1) << "is_constexpr: " << as<std::string>(n.is_constexpr) << "\n";
31553152
}
31563153

3157-
auto start(return_statement_node const& n, int indent) -> void
3154+
auto start(return_statement_node const&, int indent) -> void
31583155
{
31593156
o << pre(indent) << "return-statement\n";
31603157
}
@@ -3185,7 +3182,7 @@ class parse_tree_printer : printing_visitor
31853182
o << pre(indent+1) << "throws: " << as<std::string>(n.throws) << "\n";
31863183
}
31873184

3188-
auto start(function_returns_tag const& n, int indent) -> void
3185+
auto start(function_returns_tag const&, int indent) -> void
31893186
{
31903187
o << pre(indent) << "function returns\n";
31913188
}
@@ -3226,12 +3223,12 @@ class parse_tree_printer : printing_visitor
32263223
assert( n.declaration );
32273224
}
32283225

3229-
auto start(parameter_declaration_list_node const& n, int indent) -> void
3226+
auto start(parameter_declaration_list_node const&, int indent) -> void
32303227
{
32313228
o << pre(indent) << "parameter-declaration-list\n";
32323229
}
32333230

3234-
auto start(translation_unit_node const& n, int indent) -> void
3231+
auto start(translation_unit_node const&, int indent) -> void
32353232
{
32363233
o << pre(indent) << "translation-unit\n";
32373234
}
@@ -3241,7 +3238,7 @@ class parse_tree_printer : printing_visitor
32413238
o << pre(indent) << "UNRECOGNIZED -- FIXME\n";
32423239
}
32433240

3244-
auto end(auto const&, int indent) -> void
3241+
auto end(auto const&, int) -> void
32453242
{
32463243
// Ignore other node types
32473244
}
@@ -3272,7 +3269,7 @@ class adjust_remaining_token_columns_on_this_line_visitor
32723269
, col_offset{offset}
32733270
{ }
32743271

3275-
auto start(token& n, int indent) -> void
3272+
auto start(token& n, int) -> void
32763273
{
32773274
if (n.position().lineno == line_to_adjust_pos.lineno &&
32783275
n.position().colno >= line_to_adjust_pos.colno
@@ -3282,12 +3279,12 @@ class adjust_remaining_token_columns_on_this_line_visitor
32823279
}
32833280
}
32843281

3285-
auto start(auto const&, int indent) -> void
3282+
auto start(auto const&, int) -> void
32863283
{
32873284
// Ignore other node types
32883285
}
32893286

3290-
auto end(auto const&, int indent) -> void
3287+
auto end(auto const&, int) -> void
32913288
{
32923289
// Ignore other node types
32933290
}

source/sema.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,7 @@ class sema
792792
inside_out_parameter = {};
793793
}
794794

795-
auto start(expression_node const& n, int indent) -> void
795+
auto start(expression_node const&, int) -> void
796796
{
797797
is_out_expression = false;
798798

@@ -805,7 +805,7 @@ class sema
805805
}
806806
}
807807

808-
auto start(expression_list_node const& n, int indent) -> void
808+
auto start(expression_list_node const& n, int) -> void
809809
{
810810
// We're going to use the pointer as an iterator
811811
if (!n.expressions.empty()) {
@@ -816,7 +816,7 @@ class sema
816816
}
817817
}
818818

819-
auto end(expression_list_node const& n, int indent) -> void
819+
auto end(expression_list_node const&, int) -> void
820820
{
821821
// Unlike debug_print, here we don't assert that we visited all the
822822
// expressions in the list because visiting them all is not always needed
@@ -911,7 +911,7 @@ class sema
911911
++scope_depth;
912912
}
913913

914-
auto end(selection_statement_node const& n, int) -> void
914+
auto end(selection_statement_node const&, int) -> void
915915
{
916916
symbols.emplace_back( scope_depth, selection_sym{ false, active_selections.back() } );
917917
active_selections.pop_back();
@@ -955,12 +955,12 @@ class sema
955955
}
956956
}
957957

958-
auto start(auto const&, int indent) -> void
958+
auto start(auto const&, int) -> void
959959
{
960960
// Ignore other node types
961961
}
962962

963-
auto end(auto const&, int indent) -> void
963+
auto end(auto const&, int) -> void
964964
{
965965
// Ignore other node types
966966
}

0 commit comments

Comments
 (0)