[squid-dev] [PATCH] shuffle remaining session cache code to libsecurity
Alex Rousskov
rousskov at measurement-factory.com
Sat Apr 29 16:47:44 UTC 2017
On 04/29/2017 02:45 AM, Amos Jeffries wrote:
>> "auto" needs "const" and "&" but not "*".
> FYI: that statement does not match my experiences with auto in the
> general case.
I suspect it matches your experiences but not your interpretation of
those experiences. Squid has many examples where treating C++ as dark
magic ("I cannot explain it, but this seems to compile, and that other
approach that should have worked did not") resulted in bad or even buggy
code. To benefit from C++11, we should learn the new language features
so that we can use (or avoid) them correctly without "experiments" and
guesswork.
If something contradicts our understanding of the standard, we should
figure out why _before_ jumping to workarounds. We do not have C++ gurus
on this list (unfortunately), but we can usually figure it out
collectively. This is especially important for commonly repeated
patterns like "auto" and "move" expressions.
In this particular case, if starless "auto" does not work for pointers,
we all need to know (and avoid) that and, vice versa, if starless "auto"
works great, we all should be using that by default.
> I have in the past omitted these sugar type details
I did not talk about sugar type details (plural) that can be omitted.
The "const" and "&" are not sugar! The detail (singular) that can (and
usually should) be omitted is "*".
> and
> found that the compiler picked to use the object copy-assignment to
> duplicate the object into the 'auto' variable.
Yes, that is exactly what the compiler does: Whether you omit "*" or
not, the compiler must copy the object. Where "*" sugar is possible,
that object is the pointer.
> That may just have been
> compiler bugs, but is a nasty one anyway. So I prefer to only replace
> the type name with auto to ensure that implicit conversions are kept to
> minimal or performant ones and the nature of the variable remains
> visible to us reading it.
The nature of a pointer is its methods/operators, not "*" in its type
declaration. Otherwise, smart pointers would not be pointers. When you
add "*" to auto, you tell the reader that the variable cannot be a smart
pointer. Usually, that is not what you want to tell or enforce.
HTH,
Alex.
More information about the squid-dev
mailing list