https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110602
Bug ID: 110602
Summary: std::format and friends are accessible without std::
Product: gcc
Version: 14.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libstdc++
Assignee: unassigned at gcc dot gnu.org
Reporter: tchaikov at gmail dot com
Target Milestone: ---
following code should not compile as "format_to" should be placed in the "std"
namespace:
====8<====
#include <format>
std::string foo() {
std::string ss;
format_to(std::back_inserter(ss), "{}", 1);
return ss;
}
int main() {
return foo().size() != 1;
}
====>8====
but it compiles with gcc trunk (at the time of writing) and gcc 13.1. with
following command line options:
-std=c++23 -O2 -Wall -Wextra
or
-std=c++20 -O2 -Wall -Wextra
i also tested clang + libstdc++ and clang + libc++. all of these combinations
compiles. see https://godbolt.org/z/GhrxPx7Gz for the reproducer.
i was trying to figure out by inspecting the preprocessed source file and
messing around with a sample code below to see if we somehow opened the std
namespace in format or some files included by it but failed:
std::string foo() {
std::string ss;
auto out = std::back_inserter(ss);
// auto args = make_format_args(1, 2, 3);
// basic_format_string<char, int, int> fmt_str{"{} {}"};
auto std_args = std::make_format_args(1, 2, 3);
auto std_wargs = std::make_wformat_args(1, 2, 3);
// does not compile
// auto args = std::make_format_args(1, 2, 3);
// does not compile
// auto wargs = std::make_wformat_args(1, 2, 3);
vformat_to(out, "{} {} {}", std_args);
auto s = vformat("{}", std_args);
format_to(out, "{}", ss);
return ss;
}
it turns out make_format_args and make_wformat_args are still in "std"
namespace, while format, format_to and vformat_to can be accessed with and
without qualified with 'std'