[squid-dev] [PATCH] Broken trunk rev14778

Amos Jeffries squid3 at treenet.co.nz
Mon Aug 8 19:19:05 UTC 2016


On 9/08/2016 6:01 a.m., Alex Rousskov wrote:
> On 08/08/2016 04:43 AM, Amos Jeffries wrote:
> 
>>   r14778: Move static member Last into change() method to avoid initialization order
>>   errors when a caller uses a global InstanceId object before the library
>>   instantiating its template is initialized.
> 
> Have you seen these Last errors? Constant initialization like "static
> int Last = 0" happens before any code runs. If you saw these errors,
> there must be something special about templates in this context that I
> do not know about (and would like to learn).
> 
>   http://en.cppreference.com/w/cpp/language/constant_initialization
> 
> 
> Thank you,
> 
> Alex.
> 

I don't think the pre-initialization of simple types is the issue here.
Or maybe Last being an int and thus using that pre-initialization
instead of having a contructor symbol is the root of the compilers
confusion.

It has been occuring on the d,debian-clang farm node for the last few
weeks. Relevant part of the log output below.


libtool: compile:  ccache clang++ -DHAVE_CONFIG_H -I../../../..
-I../../../../include -I../../../../lib -I../../../../src
-I../../include -Werror -Qunused-arguments -Wno-deprecated-register
-D_REENTRANT -I/usr/include/p11-kit-1 -g -O2 -std=c++11 -MT
PoolMalloc.lo -MD -MP -MF .deps/PoolMalloc.Tpo -c
../../../../src/mem/PoolMalloc.cc  -fPIC -DPIC -o .libs/PoolMalloc.o
In file included from ../../../../src/mem/old_api.cc:26:
In file included from ../../../../src/SquidConfig.h:18:
In file included from ../../../../src/HttpHeaderTools.h:13:
In file included from ../../../../src/format/Format.h:14:
In file included from ../../../../src/sbuf/SBuf.h:14:
../../../../src/base/InstanceId.h:28:27: error: instantiation of
variable 'InstanceId<SBuf>::Last' required here, but no definition is
available [-Werror,-Wundefined-var-template]
    InstanceId(): value(++Last ? Last : ++Last) {}
                          ^
../../../../src/sbuf/SBuf.h:102:5: note: in instantiation of member
function 'InstanceId<SBuf>::InstanceId' requested here
    SBuf(SBuf&& S) : store_(std::move(S.store_)), off_(S.off_),
len_(S.len_) {
    ^
../../../../src/base/InstanceId.h:47:18: note: forward declaration of
template entity is here
    static Value Last;
                 ^
../../../../src/base/InstanceId.h:28:27: note: add an explicit
instantiation declaration to suppress this warning if
'InstanceId<SBuf>::Last' is explicitly instantiated in another
translation unit
    InstanceId(): value(++Last ? Last : ++Last) {}
                          ^
1 error generated.
Makefile:817: recipe for target 'old_api.lo' failed
make[4]: *** [old_api.lo] Error 1


The suggested declaration turns out not to e very portable, so I went
with moving the global symbol into a method.


Amos



More information about the squid-dev mailing list