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

            Bug ID: 70730
           Summary: Inconsistent column number in "error: attempt to take
                    address of bit-field structure member"
           Product: gcc
           Version: 7.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ch3root at openwall dot com
  Target Milestone: ---

When compiling this program:

/----------------------------------------------------------------------\
#include <stddef.h>

int main()
{
  struct s { int x:2; };
  typedef struct s s;

  offsetof(struct { int x:2; }, x);
  offsetof(struct s, x);
  offsetof(s, x);
}
\----------------------------------------------------------------------/

I get the following error messages:

/----------------------------------------------------------------------\
In file included from example.c:1:0:
example.c: In function ‘main’:
example.c:8:19: error: attempt to take address of bit-field structure member
‘x’
   offsetof(struct { int x:2; }, x);
                   ^
example.c:9:19: error: attempt to take address of bit-field structure member
‘x’
   offsetof(struct s, x);
                   ^
example.c:10:3: error: attempt to take address of bit-field structure member
‘x’
   offsetof(s, x);
   ^~~~~~~~
\----------------------------------------------------------------------/

In the first two cases it points inside the first argument while in the third
case it points to the 'offset' itself. This is inconsistent.

Perhaps it's better to point to the second argument instead? This is what clang
outputs:

/----------------------------------------------------------------------\
example.c:8:33: error: cannot compute offset of bit-field 'x'
  offsetof(struct { int x:2; }, x);
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
.../lib/clang/3.9.0/include/stddef.h:120:46: note: expanded from macro
'offsetof'
#define offsetof(t, d) __builtin_offsetof(t, d)
                       ~~~~~~~~~~~~~~~~~~~~~~^~
example.c:8:25: note: bit-field is declared here
  offsetof(struct { int x:2; }, x);
                        ^
example.c:9:22: error: cannot compute offset of bit-field 'x'
  offsetof(struct s, x);
  ~~~~~~~~~~~~~~~~~~~^~
.../lib/clang/3.9.0/include/stddef.h:120:46: note: expanded from macro
'offsetof'
#define offsetof(t, d) __builtin_offsetof(t, d)
                       ~~~~~~~~~~~~~~~~~~~~~~^~
example.c:5:18: note: bit-field is declared here
  struct s { int x:2; };
                 ^
example.c:10:15: error: cannot compute offset of bit-field 'x'
  offsetof(s, x);
  ~~~~~~~~~~~~^~
.../lib/clang/3.9.0/include/stddef.h:120:46: note: expanded from macro
'offsetof'
#define offsetof(t, d) __builtin_offsetof(t, d)
                       ~~~~~~~~~~~~~~~~~~~~~~^~
example.c:5:18: note: bit-field is declared here
  struct s { int x:2; };
                 ^
3 errors generated.
\----------------------------------------------------------------------/

Reply via email to