source_location::file_name is a misleading nameI think this is not suitably emphasized in cppreference...
source_location::file_name() is basically __FILE__ instead of __FILE_NAME__ (clang/gcc), which can be absolute path by default... This means if used without care, it may inject absolute path into release build. (Due to its name and c++-ish style, I doubt it's more likely to be abused than __FILE__.)https://godbolt.org/z/e149Tqv4Y
#include<sourcelocation>
#include<filesystem>
#include<stringview>
#include<cstdio>
int main() {
constexpr std::stringview filename = std::sourcelocation::current().filename();
staticassert(filename == FILE);
if (std::filesystem::path(filename).isabsolute()) {
puts(":(");
}
}
https://redd.it/1odzc93
@r_cpp