The following issue has been SUBMITTED.
======================================================================
http://public.kitware.com/Bug/view.php?id=15730
======================================================================
Reported By: nmeunier
Assigned To:
======================================================================
Project: CMake
Issue ID: 15730
Category: CMake
Reproducibility: always
Severity: minor
Priority: normal
Status: new
======================================================================
Date Submitted: 2015-09-08 08:51 EDT
Last Modified: 2015-09-08 08:51 EDT
======================================================================
Summary: 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>
======================================================================
Issue History
Date Modified Username Field Change
======================================================================
2015-09-08 08:51 nmeunier New Issue
======================================================================
--
Powered by www.kitware.com
Please keep messages on-topic and check the CMake FAQ at:
http://www.cmake.org/Wiki/CMake_FAQ
Kitware offers various services to support the CMake community. For more
information on each offering, please visit:
CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html
Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html
Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake-developers