From: Josh Triplett <josh@joshtriplett.org>
To: Christopher Li <sparse@chrisli.org>
Cc: Bernd Petrovitsch <bernd@sysprog.at>,
Kamil Dudka <kdudka@redhat.com>,
Tomas Klacko <tomas.klacko@gmail.com>,
linux-sparse@vger.kernel.org
Subject: Re: including sparse headers in C++ code
Date: Mon, 11 Oct 2010 12:12:20 -0700 [thread overview]
Message-ID: <20101011191219.GD8537@feather> (raw)
In-Reply-To: <AANLkTin00gg79Zdg1JJgaaK+2wzgu9Xpr719MYOebQ+J@mail.gmail.com>
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@sysprog.at> 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@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
next prev parent reply other threads:[~2010-10-11 19:12 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-10-09 16:40 including sparse headers in C++ code Tomas Klacko
2010-10-09 20:59 ` Josh Triplett
2010-10-09 21:46 ` Christopher Li
2010-10-10 11:41 ` Bernd Petrovitsch
2010-10-10 11:52 ` Kamil Dudka
2010-10-11 9:44 ` Bernd Petrovitsch
2010-10-11 16:04 ` Christopher Li
2010-10-11 19:12 ` Josh Triplett [this message]
2010-10-13 14:45 ` Bernd Petrovitsch
2010-10-18 18:43 ` Christopher Li
2010-10-20 7:29 ` Al Viro
2010-10-20 9:39 ` Bernd Petrovitsch
2010-10-20 15:34 ` Christopher Li
2010-10-29 13:22 ` Bernd Petrovitsch
2010-11-05 0:57 ` Christopher Li
2010-11-09 13:28 ` Bernd Petrovitsch
2010-11-09 22:52 ` Christopher Li
2010-11-10 10:52 ` Bernd Petrovitsch
2010-10-11 22:33 ` Tomas Klacko
2010-10-11 22:46 ` Al Viro
2010-10-11 23:01 ` Christopher Li
2010-10-12 22:45 ` Tomas Klacko
2010-10-13 0:37 ` Christopher Li
2010-10-13 11:39 ` Bernd Petrovitsch
2010-10-16 16:03 ` Tomas Klacko
2010-10-16 19:11 ` Josh Triplett
2010-10-17 10:31 ` Tomas Klacko
2010-10-18 4:13 ` Christopher Li
2010-10-18 5:39 ` Josh Triplett
2010-10-18 18:37 ` Christopher Li
2010-10-19 20:03 ` Tomas Klacko
2010-10-19 21:31 ` Al Viro
2010-10-19 21:46 ` David Malcolm
2010-10-19 22:12 ` Al Viro
2010-10-19 22:49 ` Tomas Klacko
2010-10-20 10:19 ` Bernd Petrovitsch
2010-10-19 23:07 ` Christopher Li
2010-10-20 7:40 ` Al Viro
2010-10-18 3:16 ` Christopher Li
2010-10-11 23:37 ` Josh Triplett
2010-10-12 10:42 ` Bernd Petrovitsch
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20101011191219.GD8537@feather \
--to=josh@joshtriplett.org \
--cc=bernd@sysprog.at \
--cc=kdudka@redhat.com \
--cc=linux-sparse@vger.kernel.org \
--cc=sparse@chrisli.org \
--cc=tomas.klacko@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).