-
Notifications
You must be signed in to change notification settings - Fork 14.9k
Closed
Labels
Description
The inline
keyword 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.
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 members are implicitly inline
};
constexpr inline int Get42() { return 42; }
// ~~~~~~
// ^ Constexpr functions are implicitly inline
static constexpr inline int NAMESPACE_STATIC = 42; // OK, constexpr static namespace scope variables are not implicitly inline