<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/81792>81792</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[-Wunsafe-buffer-usage] Incorrect fixit for unsafe pointer initialized with nullptr
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
jkorous-apple
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
jkorous-apple
</td>
</tr>
</table>
<pre>
There is a typo in test file
https://github.com/llvm/llvm-project/blob/main/clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-local-var-span.cpp#L117
`{{^3}}` should be `{{[^3]}}`
(It is copy-pasted to 3 more places in the test file.)
Some of the test cases fail when fixed and unfortunately it masks a real bug in `FixVarInitializerWithSpan`.
```
// If `Init` has a constant value that is (or equivalent to) a
// NULL pointer, we use the default constructor to initialize the span
// object, i.e., a `std:span` variable declaration with no initializer.
// So the fix-it is just to remove the initializer.
if (Init->isNullPointerConstant(Ctx,
// FIXME: Why does this function not ask for `const ASTContext
// &`? It should. Maybe worth an NFC patch later.
Expr::NullPointerConstantValueDependence::
NPC_ValueDependentIsNotNull)) {
std::optional<SourceLocation> InitLocation =
getEndCharLoc(Init, SM, LangOpts);
if (!InitLocation)
return {};
SourceRange SR(Init->getBeginLoc(), *InitLocation);
```
The problem is that for this form of initialization `int * ptr = nullptr;` the fixit removes only the "nullptr" but leaves "=" which makes the code syntactically invalid.
I can't think of a simple-enough solution that would cover all cases so filing issue for later.
`int * ptr = nullptr;`
`int * ptr {nullptr};`
The latter form is likely very uncommon but we still need to account for it.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUVlFv4jgQ_jXmZQQCp4XywAOFIiF1e6tlb3ffThNnknjr2Dl7DOV-_clJSmlVnXQoMkoynm--b8YzwRB0ZYlW4vZeSPn72XkXwxjb1pCQUtxuRxi5dn717tUod8V59b0mT6ADIPC5daAtMAWGU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