<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/72397>72397</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[FR] clang-tidy check for implicit inline
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang-tidy
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
FalcoGer
</td>
</tr>
</table>
<pre>
The [`inline` keyword](https://en.cppreference.com/w/cpp/language/inline) is widely misunderstood. On top of that there are many instances where inline is implicit. I think it's therefore best to eliminate the `inline` keyword from code where possible.
I propose a checker that checks if the `inline` keyword may be required in the context that it is in and propose a fix to remove it where it isn't.
```c++
template <typename T> inline T f()
// ~~~~~~
// ^ Templated functions behave like inline functions.
{
return T{};
}
template <> inline double f<double>() = delete;
// ~~~~~~
// ^ Deleted functions are implicitly inline
inline int g(float a) // May be OK, no diagnostic.
{
return static_cast<int>(a - 5.F);
}
inline int g(double) = delete;
//~~~~~~
//^ Deleted functions are implicitly inline
class C
{
public:
inline C& operator=(const C&) = delete;
// ~~~~~~
// ^ Deleted functions are implicitly inline.
inline int Get42() const { return 42; }
// ~~~~~~
// ^ Functions defined inside the class are implicitly inline
static constexpr inline int C_STATIC = 42;
// ~~~~~~
// ^ constexpr static is implicitly inline
};
constexpr inline int Get42() { return 42; }
// ~~~~~~
// ^ Constexpr functions are implicitly inline
static constexpr inline int NAMESPACE_STATIC = 42; // OK
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyclk1zozgQhn-NfOmKCwvwx4FDgsPU1NRstnZ8nxKiMdoIiZWaJL7sb98SYJvZZJKdpSh_INH9vk83QsJ7dTSIGUvvWLpfiJ4a67JCaGk_oVuUtjplhwYhjK8jZbQyyNYRPOLp2bqKpXvGtw1R51l8y3jBeIFmKbvOYY0OjcSltC3jxTPjhew6xgstzLEXR2S8mOLxHSgPz6pCfYJW-d5U6DxZWy3hwQDZDmw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