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

            Bug ID: 94912
           Summary: Non-consistent behaviour of VLAs compared to C
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gabravier at gmail dot com
  Target Milestone: ---

#include <stdbool.h>
#include <stdio.h>

bool f(int n)
{
    typedef int A[n];
    ++n;
    A a;
    int b[n];
    n -= 2;
    typedef int C[n];
    C c;

    return (sizeof(a) < sizeof(b)) && (sizeof(a) > sizeof(c));
}

int main()
{
        printf("%d", (int)f(10));
}

If compiled as C, this program will print 1. If compiled as C++, this program
will print 0. The C++ frontend seems to fail to take into account that the
`typedef`'s results are calculated at runtime based on the current value of
`n`.

Reply via email to