[squid-dev] [PATCH] polish Config2 using C++11 features

Amos Jeffries squid3 at treenet.co.nz
Fri Sep 30 16:58:56 UTC 2016


On 1/10/2016 5:09 a.m., Alex Rousskov wrote:
> On 09/30/2016 09:38 AM, Amos Jeffries wrote:
>> We now seem to have had several patches successfully use members
>> declared with default values and/or with the "*this = Foo();" shortcut
>> for a reset/clear method.
> 
> The *this assignment works for pre-C++11 v3.5 as well. The default
> values will not work there so we should be extra careful when
> backporting affected code.
> 
> 
>> So I think we can start using these to replace old C-style
>> initialization and clear() functions.
> 
> Agreed. I wonder whether we should be consistent -- if some class data
> members cannot use default initialization and some can, should we
> initialize _all_ members in the constructor(s)?

I was aiming towards that some years ago. But reality turned out to be
that some of the bigger classes had annoyingly long lists of members to
initialize, many of which did not exactly need it. And no compiler or
static checking detects patches that forget to set one if it was a
complex class with own default constructor (like our Pointer types,
which were frequently missed).

So these days I'm only setting the basic POD type members explicitly on
construct. If we can set them like this and skip defining a default
constructor entirely that would be even better for shrinking the code.


> 
>> This patch begins by replacing the Config2 use of memset(). I for one am
>> constantly mistaking which of the Config objects has memset() applied to
>> it at the global level when reconfigure happens. Now we do not need to
>> care, each object handles its own clearing one way or another.
> 
> +1
> 

Thanks. Will commit once it passes all the build tests.

Amos



More information about the squid-dev mailing list