From 58feaa5f529ef7c5afec8f6f323d7bcf596313a4 Mon Sep 17 00:00:00 2001 From: Martin Sebor Date: Wed, 25 Jan 2017 23:11:53 +0000 Subject: [PATCH] PR c++/71290 - Flexible array member is not diagnosed with -pedantic gcc/cp/ChangeLog: PR c++/71290 * decl.c (grokdeclarator): Warn on flexible array members. gcc/testsuite/ChangeLog: PR c++/71290 * g++.dg/ext/flexarray-mangle-2.C: Adjust. * g++.dg/ext/flexarray-mangle.C: Same. * g++.dg/ext/flexarray-subst.C: Same. * g++.dg/ext/flexary10.C: Same. * g++.dg/ext/flexary11.C: Same. * g++.dg/ext/flexary14.C: Same. * g++.dg/ext/flexary16.C: Same. * g++.dg/ext/flexary18.C: Same. * g++.dg/ext/flexary19.C: Same. * g++.dg/ext/flexary7.C: Same. * gcc/testsuite/g++.dg/cpp1z/has-unique-obj-representations1.C: Same. * gcc/testsuite/g++.dg/ubsan/object-size-1.C: Same. * gcc/testsuite/obj-c++.dg/property/at-property-23.mm: Same. From-SVN: r244910 --- gcc/cp/ChangeLog | 5 +++++ gcc/cp/decl.c | 11 +++++++++++ .../cpp1z/has-unique-obj-representations1.C | 5 ++++- gcc/testsuite/g++.dg/ext/flexarray-mangle-2.C | 3 ++- gcc/testsuite/g++.dg/ext/flexarray-mangle.C | 3 ++- gcc/testsuite/g++.dg/ext/flexarray-subst.C | 6 +++++- gcc/testsuite/g++.dg/ext/flexary10.C | 2 +- gcc/testsuite/g++.dg/ext/flexary11.C | 2 +- gcc/testsuite/g++.dg/ext/flexary14.C | 4 +++- gcc/testsuite/g++.dg/ext/flexary16.C | 5 +++-- gcc/testsuite/g++.dg/ext/flexary18.C | 2 ++ gcc/testsuite/g++.dg/ext/flexary19.C | 1 + gcc/testsuite/g++.dg/ext/flexary7.C | 8 ++++---- gcc/testsuite/g++.dg/ext/pr71290.C | 17 +++++++++++++++++ gcc/testsuite/g++.dg/ubsan/object-size-1.C | 5 ++++- .../obj-c++.dg/property/at-property-23.mm | 2 ++ 16 files changed, 67 insertions(+), 14 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ext/pr71290.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 6144ad77450..11c30ca6362 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2017-01-25 Martin Sebor + + PR c++/71290 + * decl.c (grokdeclarator): Warn on flexible array members. + 2017-01-25 Jakub Jelinek PR c++/78896 diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 4b64ba13377..39e7fbd9600 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -11804,6 +11804,17 @@ grokdeclarator (const cp_declarator *declarator, } else { + /* Array is a flexible member. */ + if (in_system_header_at (input_location)) + /* Do not warn flexible them in system headers because glibc + uses them. */; + else if (name) + pedwarn (input_location, OPT_Wpedantic, + "ISO C++ forbids flexible array member %<%s%>", name); + else + pedwarn (input_location, OPT_Wpedantic, + "ISO C++ forbids flexible array members"); + /* Flexible array member has a null domain. */ type = build_cplus_array_type (TREE_TYPE (type), NULL_TREE); } diff --git a/gcc/testsuite/g++.dg/cpp1z/has-unique-obj-representations1.C b/gcc/testsuite/g++.dg/cpp1z/has-unique-obj-representations1.C index 73d80bfc691..bca03a16c41 100644 --- a/gcc/testsuite/g++.dg/cpp1z/has-unique-obj-representations1.C +++ b/gcc/testsuite/g++.dg/cpp1z/has-unique-obj-representations1.C @@ -1,4 +1,5 @@ // { dg-do compile { target c++11 } } +// { dg-additional-options "-Wno-error=pedantic" } #define INTB (__SIZEOF_INT__ * __CHAR_BIT__) struct S { int i : INTB * 3 / 4; S (); }; @@ -7,7 +8,9 @@ struct U { int i : INTB * 3 / 4; int j : INTB / 4; }; struct V { int i : INTB * 3 / 4; int j : INTB / 4 + 1; }; struct W {}; struct X : public W { int i; void bar (); }; -struct Y { char a[3]; char b[]; }; +struct Y { + char a[3]; char b[]; // { dg-warning "forbids flexible array member" } +}; struct Z { int a; float b; }; struct A { int i : INTB * 2; int j; }; // { dg-warning "exceeds its type" } union B { long a; unsigned long b; }; diff --git a/gcc/testsuite/g++.dg/ext/flexarray-mangle-2.C b/gcc/testsuite/g++.dg/ext/flexarray-mangle-2.C index 98bd5f5da0e..3abb407fab7 100644 --- a/gcc/testsuite/g++.dg/ext/flexarray-mangle-2.C +++ b/gcc/testsuite/g++.dg/ext/flexarray-mangle-2.C @@ -1,9 +1,10 @@ // PR c++/69277 - [6 Regression] ICE mangling a flexible array member // { dg-do compile { target c++11 } } +// { dg-additional-options "-Wno-error=pedantic" } struct A { int n; - char a []; + char a[]; // { dg-warning "forbids flexible array member" } }; // Declare but do not define function templates. diff --git a/gcc/testsuite/g++.dg/ext/flexarray-mangle.C b/gcc/testsuite/g++.dg/ext/flexarray-mangle.C index d8a8c0ac59b..658d9355a9c 100644 --- a/gcc/testsuite/g++.dg/ext/flexarray-mangle.C +++ b/gcc/testsuite/g++.dg/ext/flexarray-mangle.C @@ -1,9 +1,10 @@ // PR c++/69277 - [6 Regression] ICE mangling a flexible array member // { dg-do compile } +// { dg-additional-options "-Wno-error=pedantic" } struct A { int n; - char a []; + char a[]; // { dg-warning "forbids flexible array member" } }; // Declare but do not define function templates. diff --git a/gcc/testsuite/g++.dg/ext/flexarray-subst.C b/gcc/testsuite/g++.dg/ext/flexarray-subst.C index f6446366165..6cf03a41af2 100644 --- a/gcc/testsuite/g++.dg/ext/flexarray-subst.C +++ b/gcc/testsuite/g++.dg/ext/flexarray-subst.C @@ -1,8 +1,12 @@ // PR c++/69251 - [6 Regression] ICE (segmentation fault) in unify_array_domain // on i686-linux-gnu // { dg-do compile } +// { dg-additional-options "-Wno-error=pedantic" } -struct A { int n; char a[]; }; +struct A { + int n; + char a[]; // { dg-warning "forbids flexible array member" } +}; template struct B; diff --git a/gcc/testsuite/g++.dg/ext/flexary10.C b/gcc/testsuite/g++.dg/ext/flexary10.C index f2868f3bd77..4d1ff56e49b 100644 --- a/gcc/testsuite/g++.dg/ext/flexary10.C +++ b/gcc/testsuite/g++.dg/ext/flexary10.C @@ -4,7 +4,7 @@ struct A { int n; - int a []; + int a[]; // { dg-warning "forbids flexible array member" } }; struct A foo (void) diff --git a/gcc/testsuite/g++.dg/ext/flexary11.C b/gcc/testsuite/g++.dg/ext/flexary11.C index 5bf774fb3b3..f958cc5555a 100644 --- a/gcc/testsuite/g++.dg/ext/flexary11.C +++ b/gcc/testsuite/g++.dg/ext/flexary11.C @@ -4,7 +4,7 @@ struct A { int n; - char a []; + char a[]; // { dg-error "forbids flexible array member" } }; void f () diff --git a/gcc/testsuite/g++.dg/ext/flexary14.C b/gcc/testsuite/g++.dg/ext/flexary14.C index 73653575e0a..add150a0be8 100644 --- a/gcc/testsuite/g++.dg/ext/flexary14.C +++ b/gcc/testsuite/g++.dg/ext/flexary14.C @@ -9,7 +9,9 @@ struct A { typedef int X; }; template int foo (T&, typename A::X = 0) { return 0; } -struct B { int n, a[]; }; +struct B { + int n, a[]; // { dg-error "forbids flexible array member" } +}; void bar (B *b) { diff --git a/gcc/testsuite/g++.dg/ext/flexary16.C b/gcc/testsuite/g++.dg/ext/flexary16.C index a3e040d7c1b..64a9f5d0515 100644 --- a/gcc/testsuite/g++.dg/ext/flexary16.C +++ b/gcc/testsuite/g++.dg/ext/flexary16.C @@ -1,6 +1,7 @@ // PR c++/71147 - [6 Regression] Flexible array member wrongly rejected // in template // { dg-do compile } +// { dg-options "-Wpedantic -Wno-error=pedantic" } template struct container @@ -11,7 +12,7 @@ struct container struct incomplete { int x; - elem array[]; + elem array[]; // { dg-warning "forbids flexible array member" } }; }; @@ -26,7 +27,7 @@ struct D: container { struct S { int x; - typename container::elem array[]; + typename container::elem array[]; // { dg-warning "forbids flexible array member" } }; }; diff --git a/gcc/testsuite/g++.dg/ext/flexary18.C b/gcc/testsuite/g++.dg/ext/flexary18.C index 435342541e5..4ab864d991d 100644 --- a/gcc/testsuite/g++.dg/ext/flexary18.C +++ b/gcc/testsuite/g++.dg/ext/flexary18.C @@ -211,3 +211,5 @@ struct StructUnion9 { // { dg-message "in the definition" } b2; // { dg-warning "invalid use" } } a2; // { dg-message "next member" } }; + +// { dg-prune-output "forbids flexible array member" } diff --git a/gcc/testsuite/g++.dg/ext/flexary19.C b/gcc/testsuite/g++.dg/ext/flexary19.C index 27d08ec225d..5eaf11b064d 100644 --- a/gcc/testsuite/g++.dg/ext/flexary19.C +++ b/gcc/testsuite/g++.dg/ext/flexary19.C @@ -341,3 +341,4 @@ struct S35 typedef D D2; }; +// { dg-prune-output "forbids flexible array member" } diff --git a/gcc/testsuite/g++.dg/ext/flexary7.C b/gcc/testsuite/g++.dg/ext/flexary7.C index fdea4d44eaf..1b22f21b2b6 100644 --- a/gcc/testsuite/g++.dg/ext/flexary7.C +++ b/gcc/testsuite/g++.dg/ext/flexary7.C @@ -5,7 +5,7 @@ struct FlexChar { int n; - char a[]; + char a[]; // { dg-warning "forbids flexible array member" } }; struct FlexChar ac = @@ -18,7 +18,7 @@ typedef __WCHAR_TYPE__ wchar_t; struct FlexWchar { int n; - wchar_t a[]; + wchar_t a[]; // { dg-warning "forbids flexible array member" } }; struct FlexWchar awc = @@ -27,7 +27,7 @@ struct FlexWchar awc = struct FlexInt { int n; - int a[]; + int a[]; // { dg-warning "forbids flexible array member" } }; // Verify that no warning is issued for the case when a flexible array @@ -48,7 +48,7 @@ struct FlexInt ai2 = template struct FlexT { int n; - T a[]; + T a[]; // { dg-warning "forbids flexible array member" } }; struct FlexT atc = diff --git a/gcc/testsuite/g++.dg/ext/pr71290.C b/gcc/testsuite/g++.dg/ext/pr71290.C new file mode 100644 index 00000000000..e782eb1a486 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/pr71290.C @@ -0,0 +1,17 @@ +// PR c++/71290 - [6/7 Regression] Flexible array member is not diagnosed +// with -pedantic + +// { dg-do compile }s +// { dg-options "-Wall -Wpedantic" } + +struct A +{ + int i; + int arr[]; // { dg-warning "forbids flexible array member .arr." } +}; + +template +struct B { + T n; + T a[]; // { dg-warning "forbids flexible array member .a." } +}; diff --git a/gcc/testsuite/g++.dg/ubsan/object-size-1.C b/gcc/testsuite/g++.dg/ubsan/object-size-1.C index e6cdefc5c7b..d2881d69a20 100644 --- a/gcc/testsuite/g++.dg/ubsan/object-size-1.C +++ b/gcc/testsuite/g++.dg/ubsan/object-size-1.C @@ -1,7 +1,10 @@ // { dg-do compile } // { dg-options "-Wpedantic -Wno-error=pedantic -fsanitize=undefined -fpermissive" } -struct T { int c; char d[]; }; +struct T +{ + int c; char d[]; // { dg-warning "forbids flexible array member" } +}; struct T t = { 1, "a" }; // { dg-warning "initialization of a flexible array member " } diff --git a/gcc/testsuite/obj-c++.dg/property/at-property-23.mm b/gcc/testsuite/obj-c++.dg/property/at-property-23.mm index 035cc8b10fe..0edb37b65cc 100644 --- a/gcc/testsuite/obj-c++.dg/property/at-property-23.mm +++ b/gcc/testsuite/obj-c++.dg/property/at-property-23.mm @@ -14,4 +14,6 @@ @property int a[8]; /* { dg-error "property can not be an array" } */ @property int b:8; /* { dg-error "expected" } */ @property int c[]; /* { dg-error "property can not be an array" } */ +/* { dg-error "forbids flexible array member" "flexible array member" { target \ +*-*-* } .-1 } */ @end -- 2.30.2