You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Rows of multidimensional arrays of an empty class have the same address in generated C #605
GNU C gives an empty struct size zero; the generated C does pointer arithmetic on pointers to such structs via char *, but not for pointers to arrays of them. All rows of Z a[3][2] get the same address, and a difference of two row pointers fails to compile.
Reproducing Source Code
extern"C"intprintf(constchar *, ...);
structZ {};
intmain() {
Z a[3][2];
Z (*p)[2] = a;
long d = (char *)(p + 1) - (char *)a;
printf("row 1 is %ld bytes after row 0 (expected 2)\n", d);
return d != 2;
}
Command-line Options
eccp --c++17 --g++ --exceptions t.cpp -o t && ./t
Type of Issue
[Back End] There is a problem with the generated C code.
Additional Details
Version: EDG C/C++ front end 7.0, main at commit 6a6c7f2d6bd8027f1b0c90877b4ba222fbff6642 (2026-11-15).
Actual output:
row 1 is 0 bytes after row 0 (expected 2)
Expected: row 1 is 2 bytes after row 0
Subscripts, additions, subtractions, increments/decrements and differences of pointers to rows must
be scaled by the C++ row size (computed at run time for GNU VLA rows).
The program exits nonzero when the bug is present. A fix with a regression
test is ready (branch fix/multidim-empty-class-array-rows); a PR will reference this issue.
Reproducing (Standard) Configuration(s)
linux-gcc-debug
Reproducing (Non-standard) Configuration
No response
I acknowledge that:
I have checked open issues and existing discussions before filing this report.
The reproducing source code that I have provided does not depend on headers that I have not included with my submission.
I have reduced the reproducing source code to the best of my ability.
I have selected at least one standard configuration or uploaded a non-standard configuration dump.
I understand code shared via this form is NOT confidential.
I have permission to share the reproducing source code and grant permission for the project to use the source code (or derivatives of the source code) to create tests.
I agree that any tests created using the reproducing source code (or deriatives of it) will be licensed under project license unless I included a LICENSE.txt file in my .zip or .tar.gz upload. If I included a LICENSE.txt file, any tests created using the reproducing source code will be governed by the terms of the license I provided instead.
Activity