-
Notifications
You must be signed in to change notification settings - Fork 266
Closed
Description
I was curious to see if cpp2 improvements included iterator invalidation safety so I tried the following:
#include <vector>
main: () -> int = {
v : std::vector = (1, 2, 3, 4, 5);
i : int = 0;
for (auto& item : v) {
if i > 3 {
v.resize(100);
}
i += 1;
}
}
I got the for loop syntax from other regression tests but cppfront doesn't accept it. It appears to be complaining about imbalanced parens but AFAICT they are balanced. Errors:
~/cppfront/regression-tests$ ../cppfront resize-invalidation-check.cpp2 && g++-10 -fconcepts -std=c++2a -I../include resize-invalidation-check.cpp
resize-invalidation-check.cpp2...
resize-invalidation-check.cpp2(7,21): error: unexpected text - expression-list is not terminated by ) (at ':')
resize-invalidation-check.cpp2(7,23): error: expected valid range expression after 'for' (at 'v')
resize-invalidation-check.cpp2(7,24): error: expected ; at end of statement (at ')')
resize-invalidation-check.cpp2(7,24): error: invalid statement in compound-statement (at ')')
resize-invalidation-check.cpp2(7,24): error: ill-formed initializer (at ')')
resize-invalidation-check.cpp2(3,1): error: unexpected text at end of Cpp2 code section (at 'main')
resize-invalidation-check.cpp2(2,0): error: parse failed for section starting here
resize-invalidation-check.cpp2: In function ‘int main()’:
resize-invalidation-check.cpp2:12:15: error: request for member ‘resize’ in ‘v’, which is of non-class type ‘int’
12 | }
| ^
Also not sure what prevents call to resize... in generated code v
is shadowed, not sure if this is incidental or some deliberate attempt to prevent what I'm doing?
Metadata
Metadata
Assignees
Labels
No labels