Skip to content

<format>: std::vformat_to results in exception in __msvc_string_view.hpp!_Verify_offset in version 14.44 #5644

Description

@old-pigeon

Describe the bug

Using a std::formatter with the 14.44 version of the STL throws at __msvc_string_view.hpp#L1280 when used with std::vformat_to and a second argument that follows after which is asked to be formatted, i. e. with :X.
The same code worked with 14.37. I both tested this with MSVC and with Clang 20, both throw with 14.44.

Command-line test case

#include <string>
#include <format>
#include <filesystem>

template <>
struct std::formatter<std::filesystem::path, wchar_t>
{
	constexpr auto parse(basic_format_parse_context<wchar_t>& context)
	{
		return context.end();
	}

	template <typename FormatContext>
	auto format(std::filesystem::path path, FormatContext& context) const
	{
		auto actual_path = path.wstring();

		return std::vformat_to(context.out(), L"\"{}\"", std::make_wformat_args(actual_path));
	}
};

int main()
{
	uint32_t actualErrorCode = 0xDEADBEEF;
	std::filesystem::path test{ "test" };
	wchar_t dest[256] = { '\0' };

	//                         v when not having :X here, it does not throw
	std::vformat_to(dest, L"{}{:X}", std::make_wformat_args(test, actualErrorCode));
	std::printf("%ls", dest);

	return 0;
}
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207\bin\HostX64\x64\CL.exe /c /ZI /JMC /nologo /W3 /WX- /diagnostics:column /sdl /Od /D _DEBUG /D _CONSOLE /D _UNICODE /D UNICODE /Gm- /EHsc /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /std:c++latest /permissive- /Fo"repro\x64\Debug\\" /Fd"repro\x64\Debug\vc143.pdb" /external:W3 /Gd /TP /FC /errorReport:prompt repro.cpp

Expected behavior

The output should be "test"DEADBEEF.

STL version

Microsoft Visual Studio Community 2022
Version 17.14.8

Additional context

Image

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    invalidThis issue is incorrect or by design

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions