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

This is a half-baked idea that occurred to me in the shower this
morning, but I think it's worth at least looking at.  The trouble with
squelching maybe-uninitialized warnings via initialization, when
manual inspection indicates there's no problem, is that it's hard to
be sure there really *is* no problem, or that future code changes
won't introduce a problem.  And the trouble with *not* squelching
those warnings is ... exactly the same (plus it contributes to
warnings fatigue).  Catch-22.

But what if we did something like this:

    namespace mfbt {

    #if !defined MOZ_DEBUG && !defined MOZ_VALGRIND
    template <typename T>
    using ConditionalUse = T;

    #else
    template <typename T>
    class ConditionalUse
    {
        T val;
        bool init;

    public:
        ConditionalUse() : T(), init(false)
        {
            MOZ_MAKE_MEM_UNDEFINED(&val, sizeof(T));
        }

        T operator=(const T v)
        {
            val = v;
            init = true;
            return val;
        }

        T operator T()
        {
            MOZ_ASSERT(init);
            return val;
        }

        // probably a bunch more operators
    };
    #endif
    }

Then, when you get a false-positive maybe-uninitialized warning, you
could just replace T var; with mfbt::ConditionalUse<T> var;  In a
release build, there would be no overhead; in a debug or valgrind
build you would get a prompt assertion on an invalid use.  For
particularly dangerous-to-use-uninitialized types (e.g. pointers) the
release build could specialize the template to initialize the value to
a poison pattern.

Thoughts?  I'm sure my sample code is all wrong, it's been a very long
time since I tried to write a generic wrapper template. ;-)  And as
always with me, better names for things solicited.

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

iQIcBAEBCAAGBQJTELjGAAoJEJH8wytnaapkRfIQALzeOGqarM35vfp4wCJh9jEZ
dQfE9jez4lutuEX3ELBaVUT+d+dZ/HslAbL0qLCb/cru/jvKUDnZJPgM42F9b1EI
repdD55vmZuOwIK3VQbx5RmjOYcgLPWSEgEYarW7/Kk59YDvr9Mdj3D8Ev5TFz6a
r4OnOrD6UVsbpjGMWgz4vfjIg5qjNGzC0t6PzJYi0Ha1qzYguNIiSdfSvviWz0sl
UtTpN/z+067GvzHeMH9fDH+l190yYqI8K7Pz8G+Q1rLNcTfygj0O/PmaSiPoSeaQ
alhbx3JoK1rtdONjnfweXi5IiBxCwPP6NeheHmCe2rDO6wSg0ORb6M220kJHmNZS
Nro80gj+ycHvAm/MtXAlfJhUAdO+dqf6a2O9wFQoLE5SrQvMBQlOO+a8sqvapMJB
I5NGQ9unT6qePScUvWMUvPqmSUDUenJ4u3vVeXDmu/qWzhP6vWAKgL1RiYdzjR/u
Nr5r3pBFHLlTiuDvE9LGhguBw1w3TDmdsiwWfnWmdkE+1yRGsFpQu9W4i0nSHaVR
enS+K+XmoB/nRii4TE02YvNyPcLL5/4J41dv4Adz7OHjojQSRPMslQ/bCnp4beXe
oKkJv7kvGhW9Ez+ZSkNapDySnir5Oer/DTkayqkF8i63Q7f1cPihh7UkyD9imS0v
ySu3LA7cqEdxwA423Htb
=Zidk
-----END PGP SIGNATURE-----
_______________________________________________
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform

Reply via email to