<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/116169>116169</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Is it ok to call `DiagEngine->getDiagnosticIDs()->getCustomDiagID()` with a runtime string?
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
GKxxUCAS
</td>
</tr>
</table>
<pre>
I need to create diagnostics from runtime strings. I found two ways: one is to use `clang::DiagnosticsEngine::getCustomDiagID`, the other is to use `clang::DiagnosticIDs::getCustomDiagID`. The former accepts the string in the form of `const char (&)[N]`, which cannot accept runtime strings. The latter accepts a `StringRef`, but there is a comment on that saying
```cpp
// FIXME: Replace this function with a create-only facilty like
// createCustomDiagIDFromFormatString() to enforce safe usage. At the time of
// writing, nearly all callers of this function were invalid.
unsigned getCustomDiagID(Level L, StringRef FormatString);
```
I'm not sure what it means by "nearly all callers of this function were invalid". How can I make a "valid" call to it?
`ClangTidyContext::diag` uses `DiagEngine->getDiagnosticIDs()->getCustomDiagID()` to create diagnostics from possibly runtime determined strings. It this also an "invalid" caller to that function?
Moreover, a related commit [29cb66b](https://github.com/llvm/llvm-project/commit/29cb66ba2f0b251a430941d00eea305b6d6c6966) seems to suggest against non-constant format strings.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysVM1u4zYQfhr6MoghUTZtHXRwnKg1utvD7hbodSSNJDYUaZCjOH77grSzSVy06AILGDZMEt_MfD-DIejBElVifS_WDwuceXS--uW3l5c_9ruvi8Z15-oAlqgDdtB6QiboNA7WBdZtgN67CfxsWU8Egb22Q1jCAXo32w745OCE5yCKHThLoEOEmQOBUFlr0A6i2Ili9_CG-GgHbelyPBDv58BuiveHB6EyIffAI4Hjkfz_gDs8hH-DWsK3kaB3fiIP2LZ05JCwL1OAtulffACuTxWcDQztiB6E3AqphCzF-v53sX5t7T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