[cfe-dev] An optical illusion

Manuel Klimek via cfe-dev cfe-dev at lists.llvm.org
Thu Mar 8 00:03:55 PST 2018


On Thu, Mar 8, 2018 at 8:53 AM Csaba Raduly via cfe-dev <
cfe-dev at lists.llvm.org> wrote:

> Hi all,
>
> Simon Brand's "How C++ Debuggers Work" presentation
> (https://www.youtube.com/watch?v=Q3Rm95Mk03c) 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?
>

clang-tidy seems like a good fit.


>
>
> Csaba
> --
> You can get very substantial performance improvements by not doing the
> right thing.
>    - Scott Meyers, An Effective C++11/14 Sampler
> So if you're looking for a completely portable, 100% standards-conformat
> way
> to get the wrong information: this is what you want. - Scott Meyers
> (C++TDaWYK)
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20180308/cee034fe/attachment.html>


More information about the cfe-dev mailing list