[Bug c/17426] Emit mandatory warning for manual expansions of offsetof

jsm at polyomino dot org dot uk gcc-bugzilla@gcc.gnu.org
Sun Sep 12 11:11:00 GMT 2004


------- Additional Comments From jsm at polyomino dot org dot uk  2004-09-12 11:11 -------
Subject: Re:  New: Emit mandatory warning for manual expansions
 of offsetof

On Sun, 12 Sep 2004, giovannibajo at libero dot it wrote:

> Meanwhile, it makes sense to warn people about this change, since it is a 
> widespread idiom. I propose a mandatory warning to be emitted in this case:
> 
> warning: this custom definition of offsetof is not a valid constant expression 
> in ISO C
> info: use the offsetof macro from <stddef.h> to disable this warning
> 
> JSM, I would appreciate your comments on this PR (especially, the wording of 
> the message, pedwarn vs warn, mandatory or not), before I write up the patch.

In what cases do you propose to diagnose this?  After all, it's perfectly 
valid if a constant isn't required (using the implementation-defined 
conversions between integers and pointers), and fits the long-established 
GCC extension of symbolic difference constant expressions if being used in 
a static initializer; it's only where an integer constant expression is 
required, as in bug 17396 (static array dimension) or for case labels, 
enum values, bit-field widths, null pointer constants, designators for 
array initializers, that there's a problem.  I would guess that array 
dimensions and maybe designators are the cases fake-offsetof is most 
likely to be being used in.



-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17426



More information about the Gcc-bugs mailing list