Bug 94912 - Non-consistent behaviour of VLAs in C++ mode compared to C
Summary: Non-consistent behaviour of VLAs in C++ mode compared to C
Status: RESOLVED DUPLICATE of bug 68531
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 10.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-05-02 01:12 UTC by Gabriel Ravier
Modified: 2023-08-24 21:44 UTC (History)
5 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Gabriel Ravier 2020-05-02 01:12:10 UTC
#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`.
Comment 1 Martin Sebor 2020-05-02 21:46:40 UTC
I think this is the same bug as reported in pr68531.

*** This bug has been marked as a duplicate of bug 68531 ***