Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++20 std::source_location yield different column numbers between free function and template functions

Consider the template function g() and free function f():

#include <iostream>
#include <source_location>

auto g(auto...) {
std::cout << std::source_location::current().column() << "\n";
}

auto f() {
std::cout << std::source_location::current().column() << "\n";
}

int main() {
g();
f();
}

Compiled with GCC-trunk get following output:

43
44

Why g() and f() yield different results? I expect the results are the same. Why a unit offset disappeared during the instantiation of the template?

like image 739
康桓瑋 Avatar asked Mar 19 '21 14:03

康桓瑋


1 Answers

I file a PR 99672 to GCC Bugzilla. Jakub Jelinek (one of the GCC contributor) reply me:

I think the standard doesn't specify anything about what exactly the column should be, so using different columns isn't standard violation.

but he still did a patch to fix it.

like image 200
康桓瑋 Avatar answered Oct 15 '22 06:10

康桓瑋