Skip to content

std::source_location line number wrong when used as default argument value #56379

Closed
@IGR2014

Description

@IGR2014

Consider the following code snipet (CompilerExplorer link):

#include<source_location>
#include<iostream>

void test_source_location(std::source_location src = std::source_location::current()) {
    std::cout << "called at " << src.line() << "\n";
}

int main() {
    test_source_location();
}

The output results for Clang, GCC and MSVC (left-to-right) are:
image

As you can see - both GCC and MSVC reports function INVOCATION line number, while Clang report function DECLARATION-one

Metadata

Metadata

Labels

c++20clang:frontendLanguage frontend issues, e.g. anything involving "Sema"

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions