From e4f3e069e5e43d466954989dd7509ed371914bd0 Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Fri, 6 Mar 2009 23:41:27 +0000 Subject: [PATCH] Downgrade complaints about the use of variable-sized types within a struct to an extension warning to match the behavior of GNU C, which addresses the Sema part of PR3671. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@66308 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/DiagnosticSemaKinds.def | 5 +++-- lib/Sema/SemaDecl.cpp | 20 +++++++++----------- test/Sema/struct-decl.c | 4 ++-- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/include/clang/Basic/DiagnosticSemaKinds.def b/include/clang/Basic/DiagnosticSemaKinds.def index ce40a9bfab..27708236d1 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.def +++ b/include/clang/Basic/DiagnosticSemaKinds.def @@ -774,8 +774,9 @@ DIAG(err_field_declared_as_function, ERROR, "field %0 declared as a function") DIAG(err_field_incomplete, ERROR, "field has incomplete type %0") -DIAG(err_variable_sized_type_in_struct, ERROR, - "variable sized type %0 must be at end of struct or class") +DIAG(ext_variable_sized_type_in_struct, EXTWARN, + "variable sized type %0 not at the end of a struct or class is a " + "GNU extension") DIAG(err_flexible_array_empty_struct, ERROR, "flexible array %0 not allowed in otherwise empty struct") DIAG(ext_flexible_array_in_struct, EXTENSION, diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 5e7ce52ee8..e902cbe135 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -3525,19 +3525,17 @@ void Sema::ActOnFields(Scope* S, // If this is a struct/class and this is not the last element, reject // it. Note that GCC supports variable sized arrays in the middle of // structures. - if (i != NumFields-1) { - Diag(FD->getLocation(), diag::err_variable_sized_type_in_struct) + if (i != NumFields-1) + Diag(FD->getLocation(), diag::ext_variable_sized_type_in_struct) << FD->getDeclName(); - FD->setInvalidDecl(); - EnclosingDecl->setInvalidDecl(); - continue; + else { + // We support flexible arrays at the end of structs in + // other structs as an extension. + Diag(FD->getLocation(), diag::ext_flexible_array_in_struct) + << FD->getDeclName(); + if (Record) + Record->setHasFlexibleArrayMember(true); } - // We support flexible arrays at the end of structs in other structs - // as an extension. - Diag(FD->getLocation(), diag::ext_flexible_array_in_struct) - << FD->getDeclName(); - if (Record) - Record->setHasFlexibleArrayMember(true); } } } diff --git a/test/Sema/struct-decl.c b/test/Sema/struct-decl.c index aa2d3b6342..e71a0b2b0c 100644 --- a/test/Sema/struct-decl.c +++ b/test/Sema/struct-decl.c @@ -23,13 +23,13 @@ int foo() { return f->v + f[0].v; } -// PR3642 +// PR3642, PR3671 struct pppoe_tag { short tag_type; char tag_data[]; }; struct datatag { - struct pppoe_tag hdr; //expected-error{{variable sized type 'hdr' must be at end of struct}} + struct pppoe_tag hdr; //expected-warning{{variable sized type 'hdr' not at the end of a struct or class is a GNU extension}} char data; }; -- 2.40.0