[Bug libstdc++/86008] New: std::quoted(std::basic_string_view) is missing

gcc at mattwhitlock dot name gcc-bugzilla@gcc.gnu.org
Thu May 31 01:18:00 GMT 2018


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86008

            Bug ID: 86008
           Summary: std::quoted(std::basic_string_view) is missing
           Product: gcc
           Version: 8.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gcc at mattwhitlock dot name
  Target Milestone: ---

The following code should compile without error in C++17 mode:


/* BEGIN TEST CODE */

#include <iomanip>
#include <iostream>
#include <string>
#include <string_view>

using namespace std::literals;

int main() {
    std::cout << std::quoted("foo") << '\n' // OK
              << std::quoted("bar"s) << '\n' // OK
              << std::quoted("baz"sv) << std::endl; // ERROR!
    return 0;
}

/* END TEST CODE */


The following shim allows the code above to compile, although it is sub-optimal
because it captures a std::basic_string_view by reference.

#if __cpp_lib_quoted_string_io <= 201304
namespace std {
    template<typename _CharT, typename _Traits>
    inline auto
    quoted(const basic_string_view<_CharT, _Traits> &__sv,
           _CharT __delim = _CharT('"'), _CharT __escape = _CharT('\\'))
    {
        return __detail::_Quoted_string<
                const basic_string_view<_CharT, _Traits> &, _CharT>(
                    __sv, __delim, __escape);
    }
}
#endif

The std::basic_string_view cannot be captured by value due to a static
assertion in std::__detail::_Quoted_string that requires the _String type
template argument to be a pointer or reference type.


The relevant C++ standard specifying std::quoted(std::basic_string_view) is:
https://cplusplus.github.io/LWG/issue2785


More information about the Gcc-bugs mailing list