* Impure attribute?
@ 2010-09-06 9:46 Akim Demaille
2010-09-08 0:57 ` Ian Lance Taylor
0 siblings, 1 reply; 3+ messages in thread
From: Akim Demaille @ 2010-09-06 9:46 UTC (permalink / raw)
To: gcc-help
Hi!
I have some piece of C++ code where the order of evaluation of the function arguments does matter. Unfortunately, it's very easy to forget about that, and there's also tons of places where the order is undefined, but to no harm.
Consider the following example:
int impure()
{
static int a = 0;
return a++;
};
void foo(int, int) {}
int main()
{
foo(impure(), impure());
}
Is there any way to have GCC warn about the undefined behavior? I'd be happy to tell impure is __attribute__((__impure__)) or something like that to teach it to teach me.
Thanks,
Akim
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Impure attribute?
2010-09-06 9:46 Impure attribute? Akim Demaille
@ 2010-09-08 0:57 ` Ian Lance Taylor
2010-09-10 15:25 ` Akim Demaille
0 siblings, 1 reply; 3+ messages in thread
From: Ian Lance Taylor @ 2010-09-08 0:57 UTC (permalink / raw)
To: Akim Demaille; +Cc: gcc-help
Akim Demaille <akim.demaille@gmail.com> writes:
> I have some piece of C++ code where the order of evaluation of the function arguments does matter. Unfortunately, it's very easy to forget about that, and there's also tons of places where the order is undefined, but to no harm.
>
> Consider the following example:
>
> int impure()
> {
> static int a = 0;
> return a++;
> };
>
> void foo(int, int) {}
>
> int main()
> {
> foo(impure(), impure());
> }
>
> Is there any way to have GCC warn about the undefined behavior? I'd be happy to tell impure is __attribute__((__impure__)) or something like that to teach it to teach me.
Hi Akim.
As far as I know, there is no existing warning for this sort of error.
gcc will detect obvious cases in which a variable is modified twice with
no intervening sequence points, but it won't detect them
interprocedurally.
Can you clearly define what the impure attribute would mean? In
particular, should it warn about calling the same impure function twice
without an intervening sequence point? Or should it complain about
calling any two impure functions? I'm not really sure which would be
more useful.
Ian
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Impure attribute?
2010-09-08 0:57 ` Ian Lance Taylor
@ 2010-09-10 15:25 ` Akim Demaille
0 siblings, 0 replies; 3+ messages in thread
From: Akim Demaille @ 2010-09-10 15:25 UTC (permalink / raw)
To: Ian Lance Taylor; +Cc: gcc-help
Le 8 sept. 2010 à 02:57, Ian Lance Taylor a écrit :
> Hi Akim.
Hi Ian!
Thanks for answering!
> Can you clearly define what the impure attribute would mean? In
> particular, should it warn about calling the same impure function twice
> without an intervening sequence point? Or should it complain about
> calling any two impure functions? I'm not really sure which would be
> more useful.
That's a good question... I would say that the more paranoid, the better, so I would go for #2, though in my case #1 suffices.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2010-09-10 15:25 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-09-06 9:46 Impure attribute? Akim Demaille
2010-09-08 0:57 ` Ian Lance Taylor
2010-09-10 15:25 ` Akim Demaille
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 read-only IMAP folder(s) and NNTP newsgroup(s).