This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/85182] _Static_assert is less than useful in a static inline
- From: "ajax at redhat dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Tue, 03 Apr 2018 22:04:06 +0000
- Subject: [Bug c/85182] _Static_assert is less than useful in a static inline
- Auto-submitted: auto-generated
- References: <bug-85182-4@http.gcc.gnu.org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85182
Adam Jackson <ajax at redhat dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|RESOLVED |UNCONFIRMED
Resolution|INVALID |---
--- Comment #3 from Adam Jackson <ajax at redhat dot com> ---
(In reply to joseph@codesourcery.com from comment #1)
> This is how static assertions are defined in C11, not a bug in GCC: it's a
> constraint violation if the constant expression compares equal to 0,
> regardless of the context in which the declaration appears (thus, a
> constraint violation in a function that is never called, for example).
You missed my point. The diagnostic points me to the site of the declaration of
the static inline, not of the call site. Let's make this more explicit:
---
desoxy:~/git/junkdrawer% cat -n static-assert.h
1 static inline void bar(void)
2 {
3 const int y = 0;
4 _Static_assert(y, "called bar()");
5 }
desoxy:~/git/junkdrawer% cat -n static-assert.c
1 #include "static-assert.h"
2 void foo(void) { bar(); }
desoxy:~/git/junkdrawer% gcc -O2 -c static-assert.c
In file included from static-assert.c:1:
static-assert.h: In function ‘bar’:
static-assert.h:4:5: error: static assertion failed: "called bar()"
_Static_assert(y, "called bar()");
^~~~~~~~~~~~~~
---
Don't tell me "in file A included from this spot in B, you hit a static
assert". Tell me "At this spot in A, this function defined in B hit a static
assert". Because otherwise, with a less trivial assertion, I am going to have
_no idea_ where the constraint was violated.