This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/67911] New: new expression fails to align overaligned types


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

            Bug ID: 67911
           Summary: new expression fails to align overaligned types
           Product: gcc
           Version: 6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

C++ leaves it implementation-defined whether the new expression supports
overaligned types.  The test case below shows that GCC's new accepts overligned
types without a diagnostic but doesn't align them correctly.

GCC should either issue a diagnostic when a new expression is invoked with a
type whose alignment it cannot satisfy or it should satisfy it.  The
implementation choice should also be documented in the manual.

$ cat a.cpp && /g++ -Wall -Wextra -O2 a.cpp && ./a.out 
extern "C" int printf (const char*, ...);

struct __attribute__ ((aligned (32))) X { char a [32]; };

int main ()
{
    X *p = new X ();
    if (reinterpret_cast<unsigned long>(p) & (alignof (X) - 1))
        printf ("%p not %lu-byte aligned\n", p, alignof (X));
}
0x1c81010 not 32-byte aligned


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]