4 ms·
Why disable tautological-compare? Of all the pickier warnings over the years, anecdotally I'd say it's been one that's caught an outsized number of actual bugs.
by twoodfin 10y ago
Why disable tautological-compare? Of all the pickier warnings over the years, anecdotally I'd say it's been one that's caught an outsized number of actual bugs.
>= 0 on an unsigned value is the classic one.
- byuu 10y agoIt triggers a lot in generic code (eg templates), where it's not so obvious the result is going to be tautalogical until you instantiate the template. Another time I've used it is just pure aesthetics: if(addr >= 0x0000 && addr <= 0x7fff) return ram.read(addr); if(addr >= 0x8000 && addr <= 0xbfff) return cpu.read(addr); if(addr >= 0xc000 && addr <= 0xffff) return apu.read(addr); Looks nicer than: if(addr <= 0x7fff) return ram.read(addr); if(addr >= 0x8000 && addr <= 0xbfff) return cpu.read(addr); if(addr >= 0xc000 && addr <= 0xffff) return apu.read(addr); And the compiler will delete the unnecessary comparison anyway, so there's no great reason to warn about it. And now imagine you want to make it even nicer, so you add between(addr, lo, hi) as a macro: (note: not a real example -- I wouldn't do this for this case, just for demonstrative purposes.) if(between(addr, 0x0000, 0x7fff)) ...; if(between(addr, 0x8000, 0xbfff)) ...; if(between(addr, 0xc000, 0xffff)) ...; Now you have the generic code triggering the warnings again.