[PATCH] D52135: [Clang-Tidy: modernize] Fix for modernize-redundant-void-arg: complains about variable cast to void

Jonas Toth via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Sep 17 03:24:46 PDT 2018


JonasToth added a comment.

> In https://reviews.llvm.org/D52135#1236220, @JonasToth wrote:
> 
>> Why is the cast to void diagnosed anyway? It is not an argument nor is it used in a function context. Do you have an explaination for that?
> 
> 
> Yes, this because when we find a function and the process it we are trying to get the beginning and the end of the function in terms of source location. In particular we have
> 
>    if (Function->isThisDeclarationADefinition()){
>      ...
>   }else{
>     removeVoidArgumentTokens(Result, Function->getSourceRange(),
>                                "function declaration");
>   }
> 
> 
> In this case **Function**  is nor a declaration or  definition so we fall in the else case and so we are going to take the entire **sourceRange** of **Function**.
>  The function **RedundantVoidArgCheck::removeVoidArgumentTokens** iterate over this **sourceRange** and if an occurrence of '**(void)'** is found this is replaced with** '()**'. In the our case **removeVoidArgumentTokens** will find this occurrence in (void)a.

Thank you for the clarification!



================
Comment at: test/clang-tidy/modernize-redundant-void-arg.cpp:510
+struct S_2{
+ void g_1(void) const{
+  // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: redundant void argument list in function definition [modernize-redundant-void-arg]
----------------
Nit. The formatting at the brace is a bit off.

Could you please add a testcase for a templated function as well?

```
template <typename T>
void bla(void) {

}
```

I think every possibility is then covered.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D52135





More information about the cfe-commits mailing list