Hi all,
Simon Brand's "How C++ Debuggers Work" presentation
(How C++ Debuggers work - Simon Brand - Meeting C++ 2017 - YouTube) had the following
snippet:
#include <unordered_set>
#include <string>
#include <iostream>
int main() {
std::unordered_set<std::string> set
{{"hello", "stop-the-"}};
for (auto x : set) {
std::cout << (x + " world") << '\n';
}
}
(this is a set with one string, but on Linux this fails with a
std::length_error being thrown)
I believe calling the std::string::string(Iterator, Iterator)
constructor with string literals is always wrong, because two string
literals can not define a valid range.
Which tool should be able to warn about this? A compiler warning seems
wrong, because the compiler can't know what the constructor does with
its arguments. Perhaps a job for the static analyzer?
Csaba