Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

std::format pointer error C3615: consteval function 'std::_Compile_time_parse_format_specs' cannot result in a constant expression

How to fix (stdC++20 mode VS2022)

#include <format>
#include <string>

auto dump(int *p)
{
    std::string resultstring = std::format(" p points to address {:p}", p);

resulting in:

error C3615: consteval function 'std::_Compile_time_parse_format_specs' cannot result in a constant expression
like image 996
GeePokey Avatar asked Oct 21 '25 08:10

GeePokey


1 Answers

Cast the pointer to void like this:

std::string resultstring = std::format("{:p}", (void *)p);

The problem is not with the format string itself, but rather that the templated type checking on the variable arguments FAILS for any non-void pointer types, generally with a confusing error in the header .

like image 141
GeePokey Avatar answered Oct 23 '25 21:10

GeePokey