Closed
Description
The use of C++1 alternative tokens lead to invalid Cpp2 or generated C++1 depending on use.
Currently, they're treated as identifiers. So
cppfront
emits an error if used C++1-correctly (x = y and z;
, 3 identifiers in a row is ill-formed), or emits bad C++1 code (x = and;
).
-- #304.
Minimal reproducer (https://godbolt.org/z/4dT5hre58):
and : int = 0;
Commands:
cppfront x.cpp2
clang++17 -std=c++2b -I $CPPFRONT_INCLUDE_DIR x.cpp
Expected result: Diagnose and
as reserved.
Actual result and error:
Generated C++1
//=== Cpp2 type declarations ====================================================
#include "cpp2util.h"
//=== Cpp2 type definitions and function declarations ===========================
#line 1 "x.cpp2"
extern int and;
//=== Cpp2 function definitions =================================================
#line 1 "x.cpp2"
int and {0};
x.cpp2:1:15: error: expected unqualified-id
extern int and;
^
x.cpp2:1:9: error: expected unqualified-id
int and {0};
^
2 errors generated.
Minimal reproducer (https://godbolt.org/z/WMzzjhGWM):
x : int = y and z;
Commands:
cppfront x.cpp2
Expected result: Diagnose and
as reserved, suggest &&
.
Actual result and error:
x.cpp2...
x.cpp2(1,13): error: ill-formed initializer (at 'and')
x.cpp2(1,1): error: unexpected text at end of Cpp2 code section (at 'x')
x.cpp2(1,0): error: parse failed for section starting here