public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/39462] New: check assert() at compile time if possible
@ 2009-03-14 17:18 ich at az2000 dot de
2009-03-14 17:33 ` [Bug c++/39462] " rguenth at gcc dot gnu dot org
` (6 more replies)
0 siblings, 7 replies; 10+ messages in thread
From: ich at az2000 dot de @ 2009-03-14 17:18 UTC (permalink / raw)
To: gcc-bugs
I have a lot of cases where it would be possible (more or less trivial,
depending on the situation/code) to check if an assert() would fail at compile
time. In such cases, I would want that GCC gives a warning (or an error).
I understand that it's not possible to catch all cases but on such cases where
it is easy for GCC to do such a check, I would like that GCC does it and
reports it if it would fail.
For the warning itself: The warning should point out the line where the problem
is really caused (or all lines which could cause that problem). E.g., if I have
an inline function where the assert depends on the function argument, I would
like to get the line-nr where I call that function, not the line-nr of the
assert() itself.
(Just to avoid confusion: I am aware of static asserts but these are different
things and not an option in most cases where I use assert(). Also, I don't want
to make things harder for myself to figure out always when I can use an static
assert and when not. And anyway, there are still a lot of trivial cases where a
static assert is not possible but it would be still trivial for the compiler to
see that it would fail.)
--
Summary: check assert() at compile time if possible
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: enhancement
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: ich at az2000 dot de
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39462
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/39462] check assert() at compile time if possible
2009-03-14 17:18 [Bug c++/39462] New: check assert() at compile time if possible ich at az2000 dot de
@ 2009-03-14 17:33 ` rguenth at gcc dot gnu dot org
2009-03-14 19:48 ` ich at az2000 dot de
` (5 subsequent siblings)
6 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2009-03-14 17:33 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from rguenth at gcc dot gnu dot org 2009-03-14 17:33 -------
You should be able to do this already with something like
void do_the_warning (void) __attribute__((warning("assertion always false")));
#define assert(X) \
if (__builtin_constant_p (X) \
&& !(X)) \
do_the_warning (); \
if (!(X)) abort ();
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39462
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/39462] check assert() at compile time if possible
2009-03-14 17:18 [Bug c++/39462] New: check assert() at compile time if possible ich at az2000 dot de
2009-03-14 17:33 ` [Bug c++/39462] " rguenth at gcc dot gnu dot org
@ 2009-03-14 19:48 ` ich at az2000 dot de
2009-03-14 20:25 ` rguenth at gcc dot gnu dot org
` (4 subsequent siblings)
6 siblings, 0 replies; 10+ messages in thread
From: ich at az2000 dot de @ 2009-03-14 19:48 UTC (permalink / raw)
To: gcc-bugs
------- Comment #2 from ich at az2000 dot de 2009-03-14 19:48 -------
Really thanks a lot for that hint.
I did a small assert-implementation by my own:
http://openlierox.svn.sourceforge.net/viewvc/openlierox/include/cassert?view=markup
Btw., it seems that Apples GCC (even 4.2) does not support that attribute. Any
alternative? But I guess you (GCC devs) are not responsible for that.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39462
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/39462] check assert() at compile time if possible
2009-03-14 17:18 [Bug c++/39462] New: check assert() at compile time if possible ich at az2000 dot de
2009-03-14 17:33 ` [Bug c++/39462] " rguenth at gcc dot gnu dot org
2009-03-14 19:48 ` ich at az2000 dot de
@ 2009-03-14 20:25 ` rguenth at gcc dot gnu dot org
2009-03-14 23:41 ` paolo dot carlini at oracle dot com
` (3 subsequent siblings)
6 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2009-03-14 20:25 UTC (permalink / raw)
To: gcc-bugs
------- Comment #3 from rguenth at gcc dot gnu dot org 2009-03-14 20:25 -------
The attribute is new in GCC 4.3.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39462
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/39462] check assert() at compile time if possible
2009-03-14 17:18 [Bug c++/39462] New: check assert() at compile time if possible ich at az2000 dot de
` (2 preceding siblings ...)
2009-03-14 20:25 ` rguenth at gcc dot gnu dot org
@ 2009-03-14 23:41 ` paolo dot carlini at oracle dot com
2009-03-15 0:10 ` ich at az2000 dot de
` (2 subsequent siblings)
6 siblings, 0 replies; 10+ messages in thread
From: paolo dot carlini at oracle dot com @ 2009-03-14 23:41 UTC (permalink / raw)
To: gcc-bugs
------- Comment #4 from paolo dot carlini at oracle dot com 2009-03-14 23:41 -------
Also - I admit not having studied in detail all your requirements, sorry about
that - I suppose you would be interested in static_assert, available with
-std=c++0x, in gcc4.3.x (and 4.4.x, of course):
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2004/n1720.html
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39462
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/39462] check assert() at compile time if possible
2009-03-14 17:18 [Bug c++/39462] New: check assert() at compile time if possible ich at az2000 dot de
` (3 preceding siblings ...)
2009-03-14 23:41 ` paolo dot carlini at oracle dot com
@ 2009-03-15 0:10 ` ich at az2000 dot de
2009-03-15 0:32 ` paolo dot carlini at oracle dot com
2009-03-15 0:59 ` ich at az2000 dot de
6 siblings, 0 replies; 10+ messages in thread
From: ich at az2000 dot de @ 2009-03-15 0:10 UTC (permalink / raw)
To: gcc-bugs
------- Comment #5 from ich at az2000 dot de 2009-03-15 00:10 -------
(In reply to comment #4)
> Also - I admit not having studied in detail all your requirements, sorry about
> that - I suppose you would be interested in static_assert, available with
> -std=c++0x, in gcc4.3.x (and 4.4.x, of course):
>
> http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2004/n1720.html
>
Thanks, but static_assert is not an option. It would make things only more
complicated and can not cover a lot of cases.
I also don't really understand why there is something like a static_assert (I
am not sure how much I really would use an assert outside of a function). If a
compiler would be intelligent enough to check asserts at compile time if
possible, to differ between static_assert and assert only makes it more
complicated - mostly for the programmer.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39462
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/39462] check assert() at compile time if possible
2009-03-14 17:18 [Bug c++/39462] New: check assert() at compile time if possible ich at az2000 dot de
` (4 preceding siblings ...)
2009-03-15 0:10 ` ich at az2000 dot de
@ 2009-03-15 0:32 ` paolo dot carlini at oracle dot com
2009-03-15 0:59 ` ich at az2000 dot de
6 siblings, 0 replies; 10+ messages in thread
From: paolo dot carlini at oracle dot com @ 2009-03-15 0:32 UTC (permalink / raw)
To: gcc-bugs
------- Comment #6 from paolo dot carlini at oracle dot com 2009-03-15 00:31 -------
Hey, no problem really, just wanted to let you aware that the next Standard
will deliver an assert checked at compile time. In general, if you want
something special for the next releases of the C++ Standard, I would suggest
making sure people in the appropriate places hear your voice. In general, we
(GCC Project) are mostly interested in features already standardized or
designed with that in mind.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39462
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/39462] check assert() at compile time if possible
2009-03-14 17:18 [Bug c++/39462] New: check assert() at compile time if possible ich at az2000 dot de
` (5 preceding siblings ...)
2009-03-15 0:32 ` paolo dot carlini at oracle dot com
@ 2009-03-15 0:59 ` ich at az2000 dot de
6 siblings, 0 replies; 10+ messages in thread
From: ich at az2000 dot de @ 2009-03-15 0:59 UTC (permalink / raw)
To: gcc-bugs
------- Comment #7 from ich at az2000 dot de 2009-03-15 00:58 -------
Hm yea, I thought already about that. But I cannot think of a good (and easy)
definition when an assert() should be checked at compile time and whether not.
And thus, I am not sure if that is something which belongs into the C++
standard itself.
That is why I thought it would be the best to let the compiler do such a check
if possible (and that pretty much depends on the cleverness of the compiler)
and to just accept the situation that there could be cases where the value
could be known in theory already at compile time but the compiler doesn't catch
that.
static asserts are different again (and I don't think there are of no use).
There is a common intersection between what I want and what static asserts
would offer but this intersection is small and they will not really solve the
issue that it would be still very nice if the compiler could check asserts at
compile time if possible (and in that case, I think that static asserts are
only of little use; but it's of course hard to tell that, also because if not
all compiler supports compile-time checks on asserts, a lot of people will use
static asserts as a semi-alternative).
But I could also just be wrong with these thoughts. I am not really into the
GCC development and even after about 5 years of C++ development, I still see
more and more new and different ways of doing stuff in C++.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39462
^ permalink raw reply [flat|nested] 10+ messages in thread
[parent not found: <bug-39462-4@http.gcc.gnu.org/bugzilla/>]
end of thread, other threads:[~2012-01-08 21:52 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-03-14 17:18 [Bug c++/39462] New: check assert() at compile time if possible ich at az2000 dot de
2009-03-14 17:33 ` [Bug c++/39462] " rguenth at gcc dot gnu dot org
2009-03-14 19:48 ` ich at az2000 dot de
2009-03-14 20:25 ` rguenth at gcc dot gnu dot org
2009-03-14 23:41 ` paolo dot carlini at oracle dot com
2009-03-15 0:10 ` ich at az2000 dot de
2009-03-15 0:32 ` paolo dot carlini at oracle dot com
2009-03-15 0:59 ` ich at az2000 dot de
[not found] <bug-39462-4@http.gcc.gnu.org/bugzilla/>
2011-09-29 0:05 ` paolo.carlini at oracle dot com
2012-01-08 21:52 ` pinskia at gcc dot gnu.org
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).