[cfe-dev] discriminating explicit boolean expressions from implicit boolean expressions in the AST
Richard
legalize at xmission.com
Wed Apr 1 14:27:58 PDT 2015
In article <CAENS6Eu+=d2Wafd_psrFMECWaOxHUEvLwRNg31jP5dbDSFDozA at mail.gmail.com>,
David Blaikie <dblaikie at gmail.com> writes:
> On Tue, Mar 31, 2015 at 1:01 PM, Richard <legalize at xmission.com> wrote:
> > Yes, the transformation is stylistic, but it is also human invoked.
> >
>
> clang-tidy isn't necessarily used for transformation in particular - I
> think of it more as a linter tool: suggesting problems, sometimes being
> able to provide likely solutions.
IMO, clang-tidy wouldn't be interesting at all if it didn't provide
the transformations. YMMV.
> I don't fundamentally object to a fixit hint including static_cast<bool>()
> or bool(), I'm just not sure it's necessarily better than not suggesting
> one & leaving it up to the user in cases where it's not obvious *shrug*
In the larger context, the user decides to accept the change or not.
In the short run, to me that means source control and rejecting or
accepting the changes proposed by the tool, possibly after manually
adjusting them.
In the long run, I'd like to provide options based on feedback from
using the tool.
However, no matter what, the tool should never propose a change that
results in changing the meaning of the code.
> > (Personally I don't know why people are
> > against the 'functional cast' bool(e), particularly when that's the
> > wording in the standard.)
> >
>
> I tend to treat c-style casts with more care because I know they can do
> more problematic transformations (I suppose when the target type is bool
> this isn't an issue? I'm not sure - I'd have to go back & read the spec
> about the sequence of conversions c-style casts can perform)
Hrm. Looking deeper into the standard, I see that 5.2.3 Explicit type
conversion (functional notation) [expr.type.conv] says that it treats
'bool(e)' as '(bool) e' when e is a single expression. This is a
little disappointing because the 'bool(e)' syntax was introduced in
C++ and I was under the impression that it was more like
static_cast<bool>(e), but apparently not. So I guess I should be
substituting static_cast<bool>(e) in ternary expressions when the type
of e is not directly a bool.
--
"The Direct3D Graphics Pipeline" free book <http://tinyurl.com/d3d-pipeline>
The Computer Graphics Museum <http://ComputerGraphicsMuseum.org>
The Terminals Wiki <http://terminals.classiccmp.org>
Legalize Adulthood! (my blog) <http://LegalizeAdulthood.wordpress.com>
More information about the cfe-dev
mailing list