3 ms·
That's again a disingenuous phrasing. The compiler didn't swallow any nonsense. std::format is just a function, there's no direct compiler support for this. The
by kllrnohj 5y ago
That's again a disingenuous phrasing. The compiler didn't swallow any nonsense. std::format is just a function, there's no direct compiler support for this. The {fmt} library did validation at runtime (which still needs to happen if the string isn't a constant!). The C++ working group then pushed to make it a compile time error in the cases it could be as part of promoting {fmt} into the standard library, which {fmt} did on existing C++20 compilers & that improvement has been folded into the spec.
- tialaramex 5y agoprintf() is likewise just a function. If we're not calling out std::format("{}{}",oops); as nonsense then we'd have no right to complain about printf("%s%d",oops) either. I say it is nonsense because it isn't sense.
- kllrnohj 5y agoOf course we can complain. First, std::format is already improved, so this is moot anyway. But more importantly, std::format always caught the error & threw a well defined exception. printf() does no such thing. It has no validation that your inputs matched the format spec. std::format always had that. So does std::cout & iostreams, for that matter.