https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88384
Bug ID: 88384 Summary: __alignof__ of an rvalue is different between C and C++ Product: gcc Version: 9.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: --- When compiled by the C front-end the __alignof__ (*p + 1) expression evaluates to the alignment of plain int, even if is a pointer to an overaligned integer. But when compiled by the C++ front end, the same expression evaluates to the alignment of the overaligned type of the pointer. Which one is correct? The section titled Determining the Alignment of Functions, Types or Variables in the manual doesn't explain what the effect of the operator is for rvalues. It only talks about lvalues: If the operand of __alignof__ is an lvalue rather than a type, its value is the required alignment for its type, taking into account any minimum alignment specified by attribute aligned... $ cat t.c && gcc -O2 -S -Wall -Wextra -fdump-tree-optimized=/dev/stdout t.c typedef __attribute__ ((aligned (8))) int I8; extern I8 *p; int f (void) { return __alignof__ (*p + 1); } ;; Function f (f, funcdef_no=0, decl_uid=1908, cgraph_uid=1, symbol_order=0) f () { <bb 2> [local count: 1073741824]: return 4; } $ gcc -O2 -S -Wall -Wextra -fdump-tree-optimized=/dev/stdout -xc++ t.c typedef __attribute__ ((aligned (8))) int I8; extern I8 *p; int f (void) { return __alignof__ (*p + 1); } ;; Function f (_Z1fv, funcdef_no=0, decl_uid=2300, cgraph_uid=1, symbol_order=0) f () { <bb 2> [local count: 1073741824]: return 8; }