View Issue Details [ Jump to Notes ] | [ Print ] | ||||||||
ID | Project | Category | View Status | Date Submitted | Last Update | ||||
0015730 | CMake | CMake | public | 2015-09-08 08:51 | 2016-02-01 09:10 | ||||
Reporter | nmeunier | ||||||||
Assigned To | |||||||||
Priority | normal | Severity | minor | Reproducibility | always | ||||
Status | closed | Resolution | won't fix | ||||||
Platform | Intel i7-3630QM | OS | windows | OS Version | 7 pro x64 | ||||
Product Version | CMake 3.0.2 | ||||||||
Target Version | Fixed in Version | ||||||||
Summary | 0015730: foreach() mis items from list when brackets are unclosed | ||||||||
Description | I wanted to read all lines of a file, and iterate on them. But I wasn't same account of line in my ''foreach()'' as there was in my file. The last iterated line was like a concatenation of all remaining lines of the file. The cause is the incorrect item was containing an opening bracket '['. | ||||||||
Steps To Reproduce | <code cmake> function(test_list_items _nb_lines _lines) set(_i 0) message("-- test '${_lines}'") # string(REPLACE "]" "" _lines "${_lines}") # string(REPLACE "[" "" _lines "${_lines}") foreach (_l IN LISTS _lines) math(EXPR _i "${_i}+1") message(" ${_i}: '${_l}'") endforeach() if (NOT _i EQUAL ${_nb_lines}) message(" ${_i} != ${_nb_lines}") else() message(" OK") endif() endfunction() set(_a "line-1;line-2\;;line-3 // [;line-4") test_list_items(4 "${_a}") set(_a "line-1;line-2\;;line-3 // ];line-4") test_list_items(4 "${_a}") set(_a "line-1;line-2\; // [;line-3 // ];line-4") test_list_items(4 "${_a}") set(_a "line-1;line-2\; // ];line-3 // [;line-4") test_list_items(4 "${_a}") set(_a "line-1;line-2\; // {;line-3 // };line-4") test_list_items(4 "${_a}") set(_a "line-1;line-2\;;line-3 // {;line-4") test_list_items(4 "${_a}") set(_a "line-1;line-2\;;line-3 // };line-4") test_list_items(4 "${_a}") </code> Here is the output: <code> -- test 'line-1;line-2\;;line-3 // [;line-4' 1: 'line-1' 2: 'line-2;' 3: 'line-3 // [;line-4' 3 != 4 -- test 'line-1;line-2\;;line-3 // ];line-4' 1: 'line-1' 2: 'line-2;' 3: 'line-3 // ];line-4' 3 != 4 -- test 'line-1;line-2\; // [;line-3 // ];line-4' 1: 'line-1' 2: 'line-2; // [;line-3 // ]' 3: 'line-4' 3 != 4 -- test 'line-1;line-2\; // ];line-3 // [;line-4' 1: 'line-1' 2: 'line-2; // ];line-3 // [' 3: 'line-4' 3 != 4 -- test 'line-1;line-2\; // {;line-3 // };line-4' 1: 'line-1' 2: 'line-2; // {' 3: 'line-3 // }' 4: 'line-4' OK -- test 'line-1;line-2\;;line-3 // {;line-4' 1: 'line-1' 2: 'line-2;' 3: 'line-3 // {' 4: 'line-4' OK -- test 'line-1;line-2\;;line-3 // };line-4' 1: 'line-1' 2: 'line-2;' 3: 'line-3 // }' 4: 'line-4' OK </code> | ||||||||
Additional Information | The only workaround I found is to add these transformation before the ''foreach()'': <code cmake> string(REPLACE "]" "" _lines "${_lines}") string(REPLACE "[" "" _lines "${_lines}") </code> | ||||||||
Tags | No tags attached. | ||||||||
Attached Files | |||||||||
Relationships | |
Relationships |
Notes | |
(0039377) Brad King (manager) 2015-09-09 09:47 |
This is documented behavior of ;-lists: http://www.cmake.org/cmake/help/v3.3/manual/cmake-language.7.html#lists [^] splitting on ; characters not following an unequal number of [ and ] characters It is an unfortunate legacy behavior that is too established to change now. |
(0040392) Robert Maynard (manager) 2016-02-01 09:10 |
Closing resolved issues that have not been updated in more than 4 months. |
Notes |
Issue History | |||
Date Modified | Username | Field | Change |
2015-09-08 08:51 | nmeunier | New Issue | |
2015-09-09 09:47 | Brad King | Note Added: 0039377 | |
2015-09-09 09:47 | Brad King | Status | new => resolved |
2015-09-09 09:47 | Brad King | Resolution | open => won't fix |
2016-02-01 09:10 | Robert Maynard | Note Added: 0040392 | |
2016-02-01 09:10 | Robert Maynard | Status | resolved => closed |
Issue History |
Copyright © 2000 - 2018 MantisBT Team |