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

[feat] Clang format detect when using struct XYZ instead of XYZ (typedef) #91063

Open
ilan-schemoul opened this issue May 4, 2024 · 9 comments
Labels
check-request Request for a new check in clang-tidy clang-tidy

Comments

@ilan-schemoul
Copy link

ilan-schemoul commented May 4, 2024

Hey,
It would be awesome to have an option (the name could be UseTypedefInsteafOfFullStructName) so when we have this

struct abc{};
typedef struct abc a;
int main() {
   struct abc b;
}

struct abc b; gets replaced by a b;

@github-actions github-actions bot added the clang Clang issues not falling into any other category label May 4, 2024
@EugeneZelenko EugeneZelenko added clang-tidy check-request Request for a new check in clang-tidy and removed clang Clang issues not falling into any other category labels May 4, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented May 4, 2024

@llvm/issue-subscribers-clang-tidy

Author: Ilan Schemoul (ilan-schemoul)

Hey, It would be awesome to have an option (the name could be UseTypedefInsteafOfFullStructName) so when we have this ```c struct abc{}; typedef struct abc a; int main() { struct abc b; } ``` `struct abc b;` gets replaced by "a b;"

@EugeneZelenko
Copy link
Contributor

Clang-format is not supposed to modify code.

@ilan-schemoul
Copy link
Author

Oh okay I thought as typedef was to define an alias clang-format was okay with that but I understand that you don't want a formatter to modify code.
Should this issue be closed or is there any other tool that could take care of this (clang warning flag + clangd code action) or this should be closed ?
Do you have any idea how I could implement this if it's stricly out of scope for this repo ?

@idler66
Copy link

idler66 commented May 7, 2024

struct abc{};
typedef struct abc a;
typedef struct abc x;
int main() {
struct abc b;
}
abc, a, x have different semantics.
How to do they replace each other?

@ilan-schemoul
Copy link
Author

You can specify the preference order and for example choose that if there's multiples one you always pick the first.

@idler66
Copy link

idler66 commented May 8, 2024

"always pick the first" leads to a semantic error.

@ilan-schemoul
Copy link
Author

Why ?
Should I close this issue ?

@idler66
Copy link

idler66 commented May 8, 2024

In my opinion, the issue can be closed.
Different meanings may be assigned to struct abs via a and x in projects.
And the definitions of a and x can evolve over time too.

@ilan-schemoul
Copy link
Author

Different meanings may be assigned to struct abs via a and x in projects.

Well then it's not a problem anymore ? If one of a or x definition is not struct abc then we don't pick it when we format ? I am missing the point ?

You're talking about a very specific edge case "what if someone would give two typedef to the same struct and then modify a single one of them" and even then I don't see your point still. Well if someone modify one typedef they known what they're doing I don't see the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
check-request Request for a new check in clang-tidy clang-tidy
Projects
None yet
Development

No branches or pull requests

4 participants