<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/234356>234356</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
clang-tidy is suggesting 'const' variable when not appropriate
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang-tidy
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
CarlT789
</td>
</tr>
</table>
<pre>
When using certain typedef values, clang-tidy is suggesting that array variables that are written to later should be declared as 'const'. Declaring them as 'const' leads to compiler errors, as would be expected. Sample code is below.
The types are typdefs of void*. When directly using void* as the type, no invalid warnings are generated.
I'm using Visual Studio 2026 on windows, and have manually upgraded to clang-tidy v23.1.1.
// These typedefs are from winnt.h.
// Using HANDLE or PVOID - types cause invalid const suggestions.
// Using 'void *' - type does not cause invalid const suggestions.
typedef void* PVOID;
typedef PVOID HANDLE;
int main( ) {
void* junk = nullptr;
{ // Simple example using HANDLE type. Generates false messages.
HANDLE events1 [3] { }; // says var can be declared 'const'
events1 [0] = junk;
// But when it's declared 'const', you can't assign to it.
const HANDLE events1a [3] { };
// events1a [0] = junk; // error C3892: 'events1a': you cannot assign to a variable that is const
}
{ // Intermediary 'typedef' use, Using PVOID. Generates false messages.
PVOID events2 [3] { }; // says var can be declared 'const'
events2 [0] = junk;
PVOID const events2a [3] { };
events2a [0] = junk; // error C3892: 'events2a': you cannot assign to a variable that is const
}
//
{ // Using "void *" No invalid code suggestions for 'void *' type to be declared 'const'.
const void* events3 [3] { };
events3 [0] = junk;
void const * events4 [3] { };
events4 [0] = junk;
}
return 0;
}
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJysVsFu4zYQ_Rr6MoggUbJlHXRw4qYNUGwLJN2eaXEscUuRAknZ678vSEq2N-vUC3R9MaAh37yZ9zgks1a0CrEmy0ey3C7Y6Dpt6idm5Fu5rhY7zU_13x0qGK1QLTRoHBMK3GlAjns4MDmiJfQJGsl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