Skip to content
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 result if called in a function parameter. #7562

Open
H-G-Hristov opened this issue Oct 3, 2023 · 0 comments

Comments

@H-G-Hristov
Copy link

H-G-Hristov commented Oct 3, 2023

This returns the wrong line if compiled with Apple clang 15:

#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);
}

For more info, first reported here:
llvm#68108

@H-G-Hristov H-G-Hristov changed the title Apple Clang: std::source_location returns a wrong results if called in a function parameter. Apple Clang: std::source_location returns a wrong result if called in a function parameter. Oct 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant