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

[clang-format] Invalid formatting of attribute applied through macro to lambda call operator with arguments #92661

Open
mattco98 opened this issue May 18, 2024 · 4 comments · May be fixed by #92673

Comments

@mattco98
Copy link

mattco98 commented May 18, 2024

I would expect the following code to be untouched:

#define ATTR [[clang::annotate("attr")]]
void foo()
{
    auto lambda = [] ATTR (int &arg) {};
}

However, the file gets formatted as:

#define ATTR [[clang::annotate("attr")]]
void foo() {
  auto lambda = [] ATTR(int &arg) {};
}

Lambdas without parameter lists seems to be formatted correctly, though that's not surprising as that was a valid position for attributes before C++23.

Tested on the latest commit (e90126e)

@nico
Copy link
Contributor

nico commented May 18, 2024

Almost certainly a dupe of #92657.

@mattco98
Copy link
Author

mattco98 commented May 18, 2024

Almost certainly a dupe of #92657.

Maybe, but if you replace the macros in the example with __attribute__((whatever)), it formats as expected.

e: I might have been unclear; this is specifically in regards to macros. The example is also formatted correctly if you replace the macros with [[...]]

@mattco98 mattco98 changed the title [clang-format] Invalid formatting of attribute applied to lambda call operator with arguments [clang-format] Invalid formatting of attribute applied through macro to lambda call operator with arguments May 18, 2024
@nico
Copy link
Contributor

nico commented May 19, 2024

clang-format works on a lexer level. It doesn't do preprocessing. It does not know about macros. If you put a -> after the __attribute__ (as in the other issue), that doesn't get formatted either. I'm guessing that it looks like the attribute works because it treats that as the name of the lambda and then parens of the attribute as the parameter list.

I'm guessing that this needs a call to handleAttributes() (or similar) somewhere in tryToParseLambda() when it's done parsing the capture.

@nico
Copy link
Contributor

nico commented May 19, 2024

Oh sorry, didn't see that you have a patch out for this already!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants