Skip to content

std::format create undefined-behavior [UndefinedBehaviorSanitizer] [c++20] #118805

Open
@nathan-in-code

Description

@nathan-in-code
#include <format>

int main()
{
  auto const str = std::format("{0}", -1);
}

If this mini-code is compiled with “AddressSanitizer” option, an undefined-behavior is detected.
The error only occurs with negative Integers.

Clang++-Version = 18
Option = -fsanitize=unsigned-integer-overflow
OS: Ubuntu 24.04 (64-bit)

example:

clang++-18 -fsanitize=unsigned-integer-overflow  -std=c++20 format.cpp -o my_format

output:
runtime error: negation of 4294967295 cannot be represented in type 'make_unsigned_t' (aka 'unsigned int')
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /usr/bin/../lib/gcc/x86_64-linux-gnu/14/../../../../include/c++/14/format:1099:12

Metadata

Metadata

Assignees

No one assigned

    Labels

    formatC++20 std::format or std::print, and anything related to themlibstdc++GNU libstdc++ C++ standard library

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions