-
Notifications
You must be signed in to change notification settings - Fork 10.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Apple Clang: std::source_location
returns a wrong results if called in a function parameter.
#68108
Comments
If it is only reproducible with Apple clang, please file a bug report with Apple. Do you have a complete example that you can post in this bug, instead of referring to godbolt or some other site? |
This should do: #include <iostream>
#include <string_view>
#include <source_location>
#include <fmt/core.h>
struct Logger {
Logger(std::source_location l = std::source_location::current()) : loc(std::move(l)) { }
template <typename ...Args>
void debug(std::string_view format, Args&& ...args) {
std::cout << fmt::format("{}({}) ", loc.file_name(), loc.line())
<< fmt::format(format, std::forward<Args>(args)...) << '\n';
}
private:
std::source_location loc;
};
int main() {
std::cout << sizeof(std::source_location) << '\n';
Logger().debug("{}, {}", "hello", "world");
Logger().debug("{}, {}", 10, 42);
} I hope this is Apple's Clang repository: apple#7562 |
IIRC @cor3ntin fixed that for clang 17(?) |
This has been working since clang 16 Sadly it's difficult to map a version of clang to a version of AppleClang, and I don't know how fast Apple has been at adopting Clang 16. Because this is a question for the Apple-shipped version of clang, I think we can close this issue. (apple#7562 does seem to be the appropriate place for this!) |
This is more of a question. The examples in this article as seen on Compiler Explorer (trunk) work as expected but in Xcode 15 they return the location of the
std::source_location::current()
call. Could that be a bug in Apple Clang 15.0?https://www.cppstories.com/2021/non-terminal-variadic-args/
Apple Clang 15 output (wrong):
GCC 13.2 output (correct):
Apple Clang details:
The text was updated successfully, but these errors were encountered: