id,summary,reporter,owner,description,type,status,milestone,component,version,severity,resolution,keywords,cc 11150,"string_ref::to_string is necessarily UB for a default-constructed string_ref, despite stating no preconditions",Tomalak Geret'kal,No-Maintainer,"Consider: {{{ boost::string_ref foo; auto bar = foo.to_string(); }}} As currently specified (`to_string` is not documented but in the code it seems to share the semantics of explicit string conversion, which is defined by the reference material, N3442), this invokes `std::string::string(nullptr, 0)`, which has UB because one of the preconditions of that `std::string` constructor is that the pointer not be `nullptr` or `NULL`... and default-constructing `boost::string_ref` indeed sets the relevant pointer to `NULL`. This has been fixed in newer versions of the proposal, e.g. by N3762 (seemingly accidentally): > Returns: `basic_string(str.begin(), str.end(), a)` ''Boost.StringRef'' should be updated to make the same change, otherwise invoking `.to_string()` on a default-constructed `boost::to_string` has undefined behaviour, despite there being no preconditions specified on `.to_string()`. Alternatively it could be documented that `.to_string()`'s precondition is that the `string_ref` actually refers to a string. (Thanks to Mgetz and Luc Danton on Stack Overflow for help identifying this bug.) (I tried to link to references but Trac thought I was a spammer and the Captcha did not show up.)",Bugs,closed,To Be Determined,utility,Boost 1.57.0,Problem,fixed,,