[Bug c++/11072] New: [3.4 regression] Implementation of offsetof macro

bangerth@dealii.org gcc-bugzilla@gcc.gnu.org
Tue Jun 3 01:34:00 GMT 2003


PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

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

           Summary: [3.4 regression] Implementation of offsetof macro
           Product: gcc
           Version: 3.4
            Status: UNCONFIRMED
          Severity: critical
          Priority: P1
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: bangerth@dealii.org
                CC: gcc-bugs@gcc.gnu.org
OtherBugsDependingO 10922
             nThis:

[Yet another problem with 10922. It is similar to 9881, which is why I CC:
you, Nathan.]

This fails on mainline:
-----------------------------
#include <cstddef>

template <typename> struct S {
    int i, j;
    static const unsigned int value = offsetof(S,j);
};
-----------------------------

g/x> /home/bangerth/bin/gcc-3.3-pre/bin/c++ -c y.cc

g/x> /home/bangerth/bin/gcc-3.4-pre/bin/c++ -c y.cc
y.cc:5: error: a cast to a type other than an integral or enumeration type
   cannot appear in a constant-expression


Now, in contrast to the claim in PR 10922, I can't find a place in the standard
that would mandate that the result of offsetof is an integer constant
expression. 18.1.5 only says that it can only be applied to POD types, which
certainly is the case here. However, it might be a QoI issue to really
let the result be an integral constant.

W.

PS: The expansion of offsetof yields here:
(reinterpret_cast <size_t> (&reinterpret_cast <char &>(static_cast <S *> (0)->j)));



------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.



More information about the Gcc-bugs mailing list