-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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-tidy: Apply fixes "modernize-redundant-void-arg" #2801
clang-tidy: Apply fixes "modernize-redundant-void-arg" #2801
Conversation
ab63f33
to
6309acb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 to this. Note that I remember some style guide proposals (unsure if they got in or not .. I cannot find them now, so assuming maybe abandoned) which was explicitly asking for this with the reasoning 'being able to differentiate declaration from call'.
@mspang can you fix the merge conflicts? Should be good to go after that! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally, I object to this change:
The void type is an intrinsic type just as is char, short, and long. If you declared a function with a single char parameter, you would declare it as:
int foo(char);
and invoke it as:
foo(‘c’);
similarly, when declaring a void parameter, the type should be declared explicitly:
int bar(void);
where it would be invoked as:
bar();
This style makes it easy to visually identify and differentiate, at a glance, a declaration from an invocation, particularly when you have a lot of inline implementation co-mingled with declarations.
I believe this syntax is considered obsolete. I did some quick digging and it seems Stroustrup abandoned this syntax intentionally when designing C++. On a more practical note, if we wanted to use I don't find the readability argument very convincing; arguments for brevity and consistency seem more salient to me. |
Some languages spell their unit type and instance as
Here's the cite: https://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.111.7973&rep=rep1&type=pdf
|
FWIW, I don't really care strongly about this. The only reason I made this PR is because I was going down the list of clang-tidy's modernize transformers. |
@mspang conflicts? |
C and C++ are different in this respect. C++: In the case of C++, an empty parameter list in either a declaration or a definition indicates that the function takes no arguments, and is equivalent to using a parameter list of void. C: In the case of C, an empty parameter list in a function declaration indicates that the function takes an unspecified number of parameters, while an empty parameter list in a function definition indicates that the function takes no parameters. So in C, you should never use an empty identifier list in a function declaration or definition. If a function is not meant to take any parameters, specify that by using void in the parameter list. In summary, if we want CHIP code base comply with C standard, we should keep void in the parameter list, if we only want CHIP code comply with C++ standard, then we can keep or remove void in the parameter list. |
Yep.
I think the boat has sailed on using C++... |
6309acb
to
81a8413
Compare
81a8413
to
1f40729
Compare
Problem
Declaring functions (void) is obsolete in C++.
Summary of Changes
Change (void) to () in c++ code.