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

[BUG] current "exploration" of not allowing default arguments breaks pure mode for functions wanting to use std::source_location #1189

Closed
farmerpiki opened this issue Jul 30, 2024 · 5 comments
Labels
bug Something isn't working

Comments

@farmerpiki
Copy link
Contributor

Just a sample cpp1 function that can no longer be represented in cpp2 syntax due to lack of default arguments.
If I'm wrong about this and there's a way around this please reply and close the bug, thanks!

void debug_function_name(char const *fn = std::source_location::current().function_name())
{
std::println(stderr, "calling: {}", fn);
}

@farmerpiki farmerpiki added the bug Something isn't working label Jul 30, 2024
@sookach
Copy link
Contributor

sookach commented Jul 30, 2024

As far as I'm aware cppfront currently does not support default arguments (sorry), although I don't think it should be too difficult to implement.

@gregmarr
Copy link
Contributor

See #75 for discussion of almost this exact case.

@farmerpiki
Copy link
Contributor Author

thanks for the link @gregmarr ... I guess based on that I have to stick to standard cpp syntax for source_location where I need it... guess it's the only good use of default arguments

@DyXel
Copy link
Contributor

DyXel commented Jul 30, 2024

As a workaround, you can probably use a macro that expands to your arguments + std::source_location.

@hsutter hsutter closed this as completed in 873b760 Aug 9, 2024
@hsutter
Copy link
Owner

hsutter commented Aug 9, 2024

Thanks! When it's time, it's time... default arguments are now supported, and your source_location example works (on Cpp1 compilers that have source_location):

my_function_name: (
    fn: *const char = std::source_location::current().function_name()
    )
= {
    std::cout << "calling: (fn)$\n";
}

main: (args) = {
    my_function_name();
}
//  On MSVC 2022, prints:
//      calling: int __cdecl main(const int,char **)
//  On GCC 14, prints:
//      calling: int main(int, char**)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants