+2017-01-25 Martin Sebor <msebor@redhat.com>
+
+ PR c++/71290
+ * decl.c (grokdeclarator): Warn on flexible array members.
+
2017-01-25 Jakub Jelinek <jakub@redhat.com>
PR c++/78896
}
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);
}
// { 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 (); };
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; };
// 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.
// 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.
// 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 <class>
struct B;
struct A {
int n;
- int a [];
+ int a[]; // { dg-warning "forbids flexible array member" }
};
struct A foo (void)
struct A {
int n;
- char a [];
+ char a[]; // { dg-error "forbids flexible array member" }
};
void f ()
template <class T> int foo (T&, typename A<T>::X = 0) { return 0; }
-struct B { int n, a[]; };
+struct B {
+ int n, a[]; // { dg-error "forbids flexible array member" }
+};
void bar (B *b)
{
// PR c++/71147 - [6 Regression] Flexible array member wrongly rejected
// in template
// { dg-do compile }
+// { dg-options "-Wpedantic -Wno-error=pedantic" }
template <typename>
struct container
struct incomplete {
int x;
- elem array[];
+ elem array[]; // { dg-warning "forbids flexible array member" }
};
};
{
struct S {
int x;
- typename container<T>::elem array[];
+ typename container<T>::elem array[]; // { dg-warning "forbids flexible array member" }
};
};
} b2; // { dg-warning "invalid use" }
} a2; // { dg-message "next member" }
};
+
+// { dg-prune-output "forbids flexible array member" }
typedef D D2;
};
+// { dg-prune-output "forbids flexible array member" }
struct FlexChar {
int n;
- char a[];
+ char a[]; // { dg-warning "forbids flexible array member" }
};
struct FlexChar ac =
struct FlexWchar {
int n;
- wchar_t a[];
+ wchar_t a[]; // { dg-warning "forbids flexible array member" }
};
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
template <class T>
struct FlexT {
int n;
- T a[];
+ T a[]; // { dg-warning "forbids flexible array member" }
};
struct FlexT<char> atc =
--- /dev/null
+// 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 <class T>
+struct B {
+ T n;
+ T a[]; // { dg-warning "forbids flexible array member .a." }
+};
// { 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 " }
@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