https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85182

            Bug ID: 85182
           Summary: _Static_assert is less than useful in a static inline
           Product: gcc
           Version: 8.0.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ajax at redhat dot com
  Target Milestone: ---

Consider:

---
desoxy:~/git/junkdrawer% cat -n static-assert.h
     1  static inline void bar(void)
     2  {
     3      _Static_assert(0, "called bar()");
     4  }
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:3:5: error: static assertion failed: "called bar()"
     _Static_assert(0, "called bar()");
     ^~~~~~~~~~~~~~
desoxy:~/git/junkdrawer% gcc --version | head -1
gcc (GCC) 8.0.1 20180317 (Red Hat 8.0.1-0.19)
---

Note that the report locates the definition, not the call site. Effectively I'm
being punished for avoiding the preprocessor, which seems wrong:

---
desoxy:~/git/junkdrawer% cat -n static-assert.h
     1  #define bar() do { \
     2          _Static_assert(0, "called bar()"); \
     3      } while (0)
desoxy:~/git/junkdrawer% gcc -O2 -c static-assert.c
In file included from static-assert.c:1:
static-assert.c: In function ‘foo’:
static-assert.h:2:9: error: static assertion failed: "called bar()"
         _Static_assert(0, "called bar()"); \
         ^~~~~~~~~~~~~~
static-assert.c:2:18: note: in expansion of macro ‘bar’
 void foo(void) { bar(); }
                  ^~~
---

Reply via email to