https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120097
Bug ID: 120097 Summary: source_location line is wrong when used in an initializer list Product: gcc Version: 14.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: eugene at hutorny dot in.ua Target Milestone: --- Created attachment 61294 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=61294&action=edit Source file with all temps When a std::source_location is instantiated within an initializer list using default value via std::source_location::current(), it gets line number from the initializer list, not from the item's line number. When this example: (see also at https://godbolt.org/z/Wcsnsoe8E) #include<source_location> #include<iostream> struct foo { constexpr foo(std::source_location lo = std::source_location::current()) : l { lo } {} std::source_location l; }; constexpr std::initializer_list<foo> slc = { {}, {}, {}, }; int main() { for(auto i : slc) { std::cout << i.l.file_name() << ':' << i.l.line() << '\n'; } } is built with clang or msvc, it prints different line numbers, corresponding to list items. With gcc it prints onle line number corresponding the the end of the list.