Author vstinner
Recipients colesbury, gregory.p.smith, serhiy.storchaka, vstinner
Date 2020-04-01.13:36:29
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1585748189.77.0.64919184097.issue40120@roundup.psfhosted.org>
In-reply-to
Content
The following C++ code fails to build:
---
#ifdef __cplusplus
#  include <cstdlib>
#else
#  include <stdlib.h>
#endif

#ifdef __cplusplus
extern "C" {
#endif

typedef struct {
    int x;
    int y;
    char array[];
} mystruct_t;

#ifdef __cplusplus
}
#endif

int main()
{
    size_t size = 2;
    mystruct_t *obj = (mystruct_t *)malloc(sizeof(mystruct_t) - 1 + size);
    obj->array[0] = 'O';
    obj->array[1] = 'K';
    free(obj);
    return 0;
}
---

Error:
---
$ LANG= g++ -pedantic -Werror x.cpp
x.c:14:10: error: ISO C++ forbids flexible array member 'array' [-Werror=pedantic]
   14 |     char array[];
      |          ^~~~~
cc1plus: all warnings being treated as errors
---
History
Date User Action Args
2020-04-01 13:36:29vstinnersetrecipients: + vstinner, gregory.p.smith, serhiy.storchaka, colesbury
2020-04-01 13:36:29vstinnersetmessageid: <1585748189.77.0.64919184097.issue40120@roundup.psfhosted.org>
2020-04-01 13:36:29vstinnerlinkissue40120 messages
2020-04-01 13:36:29vstinnercreate