- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The following program:
#include <set> #include <iostream> std::set<std::string> Foo() { std::set<std::string> ret; ret.insert("test"); return ret; } int main(int argc, char** argv) { while (true) { for(auto& s : Foo()) { // do nothing. } } return 0; }
Leaks memory and causes my system to swap after a few seconds. This is on Linux x86_64, ICC Version 17.0.1, GCC Version 6.3.0. I compile like this:
icpc -o test test.C
Compiling the same program with g++ does not show this leak. Any ideas? Is there a bug in the compiler?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This is a known defect with temporaries and range based for loops in 17.0 update 1.
It is fixed in the soon to be release update 2.
Sorry for the inconvenience.
See this post for a detailed discussion of the bug:
https://software.intel.com/en-us/forums/intel-c-compiler/topic/705086
Judy
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The bug goes away in this version:
#include <set> #include <iostream> std::set<std::string> Foo() { std::set<std::string> ret; ret.insert("test"); return ret; } int main(int argc, char** argv) { while (true) { std::set<std::string> foo = Foo(); for(auto& s : foo) { // do nothing. } } return 0; }
i.e. when first storing the result of Foo() in a temporary.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Bug confirmed!
I wish someone from Intel could look into this and check.
The same happens when using a std::vector<std::string> instead of std::set<std::string>. Same sympton: when bining to a local variable before the range-based for loop, there is no issue, otherwise it leaks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This is a known defect with temporaries and range based for loops in 17.0 update 1.
It is fixed in the soon to be release update 2.
Sorry for the inconvenience.
See this post for a detailed discussion of the bug:
https://software.intel.com/en-us/forums/intel-c-compiler/topic/705086
Judy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks a lot Judy!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you Judy, we have applied a workaround along the lines of the second code snippet I posted and are looking forward to 17.0. Update 2.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for the additional tests Sergey, I believe with 17.0 Update 1 and GCC 6.3.0 -std=c++11 is default so I didn't add it in the flags.
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page