There is a certain Vector2<T> class with an overloaded operator (perhaps a similar behavior with ordinary functions, but due to unpredictable behavior (more on that later) we could not reliably be verified):
template <typename T> class Vector2 { ... template <typename> // объявляем дружественную ф-цию шаблонной friend Vector2<T> operator +(Vector2<T> const& l_v, Vector2<T> const& r_v); ... } I will pay attention to the form of recording a constant link - T const& a , and not const T& val . Then it will play an important role.
But when trying to describe this f-tion, namely:
template <typename T> Vector2<T> operator +(Vector2<T> const& l_v, Vector2<T> const& r_v) { ... } the most interesting begins, namely the absolutely unpredictable behavior of code analysis "on the fly", from similar code generations when trying to automatically implement the declared function:
template <typename> Vector2<T> operator+(Vector2 < T > const & l_v, Vector2<T> const& r_v ) { return Vector2<T>(); } // да-да, именно в таком виде, со всеми отступами until a categorical refusal to analyze the code, underlining every second word in red.
In general, sometimes (very rarely), CLion perceives everything correctly, but after a while it begins to degrade again.
And now to T const& a . The fact is that if we change the entry in the description of the function to const T& a , then everything will work more than normally. The type of record in the declaration of the function does not affect in any way.
Of course, you could just go to the record of the form const T& a , and the code is compiled, and this is only visual help from this IDE, but I would not write this question if I did not want to solve this problem, so I would like understand how to do this.
PS
CLion version 2018.1, but also tested on 2018.1.6, on a different device, where the result was the same.