Skip to content

Commit cb8c1c5

Browse files
committed
Reclaim alternative names for users, closes #328
Another thing there's no need to support anymore and that we shouldn't have to teach... these haven't been needed since the 1980s. Normally we don't have to teach things that compilers treat as errors, because they don't compile, but this is a case where the error is surprising and so we still have to teach it (i.e., when users trip across trying to use a common word like `and` as a variable name and wonder why it's an error and then it's a whole thing again)
1 parent 4f68962 commit cb8c1c5

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

source/cppfront.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1447,12 +1447,31 @@ class cppfront
14471447

14481448
declaration_node const* decl = {};
14491449

1450+
// 'new' is a named allocator object
14501451
if (n == "new") {
14511452
printer.print_cpp2("cpp2_new", pos);
14521453
}
1454+
// 'this' is not a pointer
14531455
else if (n == "this") {
14541456
printer.print_cpp2("(*this)", pos);
14551457
}
1458+
// Reclaim the alternative names for users
1459+
else if (
1460+
n == "and"
1461+
|| n == "and_eq"
1462+
|| n == "bitand"
1463+
|| n == "bitor"
1464+
|| n == "compl"
1465+
|| n == "not"
1466+
|| n == "not_eq"
1467+
|| n == "or_eq"
1468+
|| n == "or_eq"
1469+
|| n == "xor"
1470+
|| n == "xor_eq"
1471+
)
1472+
{
1473+
printer.print_cpp2(n.to_string(true) + "_", pos);
1474+
}
14561475
else if (
14571476
current_declarations.back()
14581477
&& (decl = current_declarations.back()->get_decl_if_type_scope_object_name_before_a_base_type(n))

0 commit comments

Comments
 (0)