Re: including sparse headers in C++ code

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Oct 11, 2010 at 09:04:18AM -0700, Christopher Li wrote:
> On Mon, Oct 11, 2010 at 2:44 AM, Bernd Petrovitsch <bernd@xxxxxxxxxx> wrote:
> > ---- Âsnip Â----
> > {102}egrep -wc 'false|true' *.[ch] | grep -v :0
> > compile-i386.c:19
> > evaluate.c:13
> > expand.c:10
> > flow.c:10
> > inline.c:13
> > linearize.c:6
> > pre-process.c:3
> > show-parse.c:3
> > simplify.c:9
> > symbol.c:1
> > tokenize.c:1
> > ---- Âsnip Â----
> > There are perhaps false positives in there - but not all.
> >
> > Perhaps 'sparse' should warn if one names variables, functions, and
> > similar "true", "false" or with any other C99 keyword.
> > For C++ keywords, a different option is probably best.
> 
> Those are not used in header files they should be fine. Sparse uses
> C99 extensively
> so it is likely it can't compile as C++ any way. I see no reason to
> compile sparse
> with C++.

Actually, Sparse seems to use "true" and "false" as variable names in
several cases; for instance:

static struct symbol *evaluate_conditional_expression(struct expression *expr)
{
        struct expression **true;
[...]
        true = &expr->conditional;


I think this only works because evaluate.c doesn't include stdbool.h.
And sure enough, if I include stdbool.h from evaluate.c:

     CC       evaluate.o
evaluate.c: In function âevaluate_conditional_expressionâ:
evaluate.c:1081: error: expected identifier or â(â before numeric constant
evaluate.c:1095: error: lvalue required as left operand of assignment
evaluate.c:1101: error: lvalue required as left operand of assignment
evaluate.c:1106: error: invalid type argument of âunary *â (have âintâ)
evaluate.c:1114: error: invalid type argument of âunary *â (have âintâ)
evaluate.c:1116: error: invalid type argument of âunary *â (have âintâ)
evaluate.c:1116: error: invalid type argument of âunary *â (have âintâ)
evaluate.c:1122: error: invalid type argument of âunary *â (have âintâ)
evaluate.c:1126: error: invalid type argument of âunary *â (have âintâ)
evaluate.c:1126: error: invalid type argument of âunary *â (have âintâ)
evaluate.c:1133: error: invalid type argument of âunary *â (have âintâ)
evaluate.c:1134: error: invalid type argument of âunary *â (have âintâ)
evaluate.c:1134: error: invalid type argument of âunary *â (have âintâ)
evaluate.c:1202: error: invalid type argument of âunary *â (have âintâ)
evaluate.c:1202: error: invalid type argument of âunary *â (have âintâ)


I agree with Bernd: I think Sparse should have a warning for using
"true", "false", or "bool" as an identifier of any kind.  That would
necessitate some way to avoid such warnings for the actual definitions
in stdbool.h.  Alternatively, Sparse could warn about using "true" or
"false" as anything other than values, and about using "bool" as
anything other than a type; that would allow for projects that define
their own bool in a compatible way.

- Josh Triplett
--
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Newbies FAQ]     [LKML]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Trinity Fuzzer Tool]

  Powered by Linux