User: Password:
|
|
Subscribe / Log in / New account

A longstanding GnuTLS certificate validation botch

A longstanding GnuTLS certificate validation botch

Posted Mar 7, 2014 16:28 UTC (Fri) by krake (subscriber, #55996)
In reply to: A longstanding GnuTLS certificate validation botch by khim
Parent article: A longstanding GnuTLS certificate validation botch

And why would I want to do that?

Even if anyone would want to do that for whatever reason, then they would simply not activate the check for actual boolean conditions.

While everyone not doing something like that would have additional type safety, either as warning but ideally as an error.


(Log in to post comments)

A longstanding GnuTLS certificate validation botch

Posted Mar 7, 2014 16:55 UTC (Fri) by jwakely (guest, #60262) [Link]

> And why would I want to do that?

Because it's a very useful idiom, very commonly used in real C++ programs.

It's useful for the same reasons that C++ and C99 don't require you to declare all variables at the start of a block: the variable is declared as soon as you need it (in the block following the condition) and is not in scope afterwards.

It gets even more useful with smart pointers and other RAII types:

if (std::shared_ptr<X> x = getX()) {
   // do stuff with *x
}
// x no longer in scope and resources already cleaned up 
Importantly, std::shared_ptr is only contextually convertible to bool, so it can be tested in contexts such as if conditions, but bool b = x; will not compile, which gives the type safety that is missing from built-in pointer types. If built-in pointer types were contextually convertible to bool that would probably make everyone happy, except for a few programs foolishly relying on implicit (non-contextual) conversions.

A longstanding GnuTLS certificate validation botch

Posted Mar 7, 2014 17:01 UTC (Fri) by krake (subscriber, #55996) [Link]

Yes, sorry, I know about the use cases, I just don't find them really convincing.

In any case, allowing that for those who want is does not prohibit additional safety for those who prefer that.
Yet I am not aware of any compiler even having a warning flags for "not a boolean in condition"

Something like -Wimplicit-bool or --no-implicit-bool would be really nice for those of us who prefer to write boolean expression for boolean conditions.


Copyright © 2017, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds