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-tidy: Apply fixes "modernize-redundant-void-arg" #2801

Conversation

mspang
Copy link
Contributor

@mspang mspang commented Sep 24, 2020

Problem

Declaring functions (void) is obsolete in C++.

Summary of Changes

Change (void) to () in c++ code.

@mspang mspang force-pushed the for-chip/clang-tidy-modernize-redundant-void-arg branch 2 times, most recently from ab63f33 to 6309acb Compare September 24, 2020 17:52
Copy link
Contributor

@andy31415 andy31415 left a 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'.

@rwalker-apple
Copy link
Contributor

@BroderickCarlin
Copy link
Contributor

@mspang can you fix the merge conflicts? Should be good to go after that!

Copy link
Contributor

@gerickson gerickson left a 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.

@mspang
Copy link
Contributor Author

mspang commented Sep 28, 2020

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 (void), it would be good to do so consistently, but I unfortunately don't think there's a tool to convert the other way.

I don't find the readability argument very convincing; arguments for brevity and consistency seem more salient to me.

@mspang
Copy link
Contributor Author

mspang commented Sep 28, 2020

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 (void), it would be good to do so consistently, but I unfortunately don't think there's a tool to convert the other way.

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 () (although void is not really a unit type, it has no value).

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++.

Here's the cite: https://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.111.7973&rep=rep1&type=pdf

On a more practical note, if we wanted to use (void), it would be good to do so consistently, but I unfortunately don't think there's a tool to convert the other way.

I don't find the readability argument very convincing; arguments for brevity and consistency seem more salient to me.

@mspang
Copy link
Contributor Author

mspang commented Sep 28, 2020

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.

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 (void), it would be good to do so consistently, but I unfortunately don't think there's a tool to convert the other way.
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 () (although void is not really a unit type, it has no value).

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++.

Here's the cite: https://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.111.7973&rep=rep1&type=pdf

On a more practical note, if we wanted to use (void), it would be good to do so consistently, but I unfortunately don't think there's a tool to convert the other way.
I don't find the readability argument very convincing; arguments for brevity and consistency seem more salient to me.

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.

@rwalker-apple
Copy link
Contributor

@mspang conflicts?

@yufengwangca
Copy link
Contributor

C and C++ are different in this respect.

C++:
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4296.pdf
"8.3.5 Functions [dcl.fct]
...
4 The parameter-declaration-clause determines the arguments that can be specified, and their processing, when the function is called. [ Note: the parameter-declaration-clause is used to convert the arguments specified on the function call; see 5.2.2. — end note ] If the parameter-declaration-clause is empty, the function takes no arguments. A parameter list consisting of a single unnamed parameter of non-dependent type void is equivalent to an empty parameter list. "

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:
http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf
"6.7.6.3 Function declarators (including prototypes)
...
10 The special case of an unnamed parameter of type void as the only item in the list specifies that the function has no parameters.
...
14 An identifier list declares only the identifiers of the parameters of the function. An empty list in a function declarator that is part of a definition of that function specifies that the function has no parameters. The empty list in a function declarator that is not part of a definition of that function specifies that no information about the number or types of the parameters is supplied.145)"

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.

@mspang
Copy link
Contributor Author

mspang commented Sep 29, 2020

C and C++ are different in this respect.

Yep.

C++:
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4296.pdf
"8.3.5 Functions [dcl.fct]
...
4 The parameter-declaration-clause determines the arguments that can be specified, and their processing, when the function is called. [ Note: the parameter-declaration-clause is used to convert the arguments specified on the function call; see 5.2.2. — end note ] If the parameter-declaration-clause is empty, the function takes no arguments. A parameter list consisting of a single unnamed parameter of non-dependent type void is equivalent to an empty parameter list. "

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:
http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf
"6.7.6.3 Function declarators (including prototypes)
...
10 The special case of an unnamed parameter of type void as the only item in the list specifies that the function has no parameters.
...
14 An identifier list declares only the identifiers of the parameters of the function. An empty list in a function declarator that is part of a definition of that function specifies that the function has no parameters. The empty list in a function declarator that is not part of a definition of that function specifies that no information about the number or types of the parameters is supplied.145)"

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.

I think the boat has sailed on using C++...

@mspang mspang force-pushed the for-chip/clang-tidy-modernize-redundant-void-arg branch from 6309acb to 81a8413 Compare September 29, 2020 05:56
@mspang mspang force-pushed the for-chip/clang-tidy-modernize-redundant-void-arg branch from 81a8413 to 1f40729 Compare September 29, 2020 22:10
@rwalker-apple rwalker-apple merged commit b0e38c2 into project-chip:master Sep 30, 2020
@mspang mspang deleted the for-chip/clang-tidy-modernize-redundant-void-arg branch September 30, 2020 22:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants