-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

On 02/28/2014 06:04 PM, Botond Ballo wrote:
>>> Is there a way to make the template generate 'T var = var;' in
>>> the release case when there's no initializer? That's be a
>>> useful hack to silence -Wunused-variable,
>>> -Wsometimes-uninitialized, etc. on gcc and clang.
>> 
>> I'm not aware of any way to do that, but I am certainly not the 
>> cleverest C++ template guy in the room.
> 
> Can't you do
> 
> : val(val)
> 
> in the initializer list?

I was expecting that you couldn't, but the true answer is "you can but
it doesn't suppress the warning":

    template <typename T>
    struct Hmm
    {
      T val;
      Hmm() : val(val) {}
    };

    int main(int argc, char **argv)
    {
      Hmm<int> x;
      if (argc > 1)
        return x.val;
    }

=>

test.cc:12:14: warning: ‘x.Hmm<int>::val’ may be used uninitialized in
this function

And in fact your original suggested hack doesn't seem to work anymore
either:

    int main(int argc, char **argv)
    {
      int x = x;
      if (argc > 1)
         return x;
    }

=>

test.cc:3:11: warning: ‘x’ is used uninitialized in this function
[-Wuninitialized]
   int x = x;
           ^

Note how it's now warning on the *hack itself*.

On another note, I noodled around with the proposed wrapper class a
bit and I hit what may be an insurmountable problem:  What do you do
if someone takes a pointer or reference to a wrapped variable?  You
can't return a smart pointer, because it'll presumably be assigned to
a bare pointer; you don't want to unconditionally require a prior set,
because it might be about to be used as an out-parameter or some such
(I fully expect that happens *all the time* in our codebase).  Maybe
something not entirely unlike getter_AddRefs?  Would that be too annoying?

zw
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1
Comment: Using GnuPG with Icedove - http://www.enigmail.net/

iQIcBAEBCAAGBQJTER/cAAoJEJH8wytnaapkxIEQALTmy9iLCywRdUGERApoBQDw
JZdrVLH3c88o3S4C6yfiklMal1Ps8cZGYL95L2YMgqqfFad0FnVO5QdLgdn/wfvU
X+ro5L0lSWLYyCnb/aEPIAXJ8lDIVHUiy4b4A5KRrB0FYtf5k1wsBwY61DYij8Of
7TqKPQa/ny5GC1cjte0gnp6+3nh/U5hrPvixg865stIObfnj946lRbfP4yPSguJX
l5c4JJPyA8MdXo+hnvcNaM9dPIAtmolGuHDRqukbv2wLk4nuHFq9/64gpYl8LfT9
wXP0aEvFAHicHyWYMIa4yW4WuygKyfRPrsvAsWV6mZeDzJbgfnYqZdENkkcBRwQt
gBQER8p6IXNeTcbDAz9G4/c/i/doY+Qb3XCt+aU8hJWpW1Ia61BoXdZT8j91MV+M
xLoCJpzygVHaFZopy0qhz+otpmxQrsEqd2Byx9QtfKfoUIiliHAIEJG4QnBI9ZPb
CjEkfOd0hKZrTzB7jsVPUCtTvuZzz6p7cQL93utiYPMeoCsmKiLiPwrjlwzK64Ww
3t9cTYJZP6Xe2p9a1hJxXbx12se1r70zruGSxe1SV+a7FVqQWU9g4H6NVgW9JnZG
GwQSCtX3Qel8WVOqXVdivi9zI8/N4WrUrlONDmjmlK0+HRpKMlyHSqvDXGSuzkvV
xVLTvZcfIIQPnuxl0OgR
=72Ca
-----END PGP SIGNATURE-----
_______________________________________________
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform

Reply via email to