From patchwork Wed Jan 25 17:02:23 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Sebor X-Patchwork-Id: 719758 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3v7rvj4LVdz9sD6 for ; Thu, 26 Jan 2017 04:02:39 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="xEbHQXmB"; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :subject:to:message-id:date:mime-version:content-type; q=dns; s= default; b=W0a2Qupd5Su+rKnx+SJ2IZ72jniX3a9C22JyHJDwmDeJpDOWpx83i SV5JdFVKlfh2YbiYyo6vlVsKlF8pDtMNgFQC/9CLhL2czMgIVu17DkUymhlU9/of D9N+NVuezgQ4X+XeRqKXcRCHArm4qbTBv3+VtwsYbWPRuD2Hm+QX04= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :subject:to:message-id:date:mime-version:content-type; s= default; bh=otE66r9GFnKj1M7UZbHVxzwEILk=; b=xEbHQXmBy3poK8IhoJEQ IUVNhUvf8WOhqJJZgsZYfkW822RHx7JRgtdtYcvqspq46a9l1gJXvBv5xMB2jfzk 9OjxNgCfq2Qyn3L+Z77BDNEQs9u90TOzQBhx408UwtlzDRcApV5feFxPxBvASXoq uJ/47IS4wo1T5s3fPAGjIDw= Received: (qmail 6677 invoked by alias); 25 Jan 2017 17:02:29 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 6649 invoked by uid 89); 25 Jan 2017 17:02:28 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.3 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_LOW, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=no version=3.3.2 spammy=atc, 3413 X-HELO: mail-qt0-f176.google.com Received: from mail-qt0-f176.google.com (HELO mail-qt0-f176.google.com) (209.85.216.176) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 25 Jan 2017 17:02:26 +0000 Received: by mail-qt0-f176.google.com with SMTP id v23so26780943qtb.0 for ; Wed, 25 Jan 2017 09:02:26 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:subject:to:message-id:date:user-agent :mime-version; bh=gw7jYdhAoM6ECPvQpU3bH1sIRjze/FB4NTpYA7G9wxE=; b=GC9jc5JBYT6a0U3zfCpeyWD3Etamcfxqk7RAyeZhFjDxNSGU858vIdAUvoiuBpgCAV hu6yDJoDaGQ+44ybRBVF8Jg6KKNwTd21m0IIN+ErEbGFKNGTVVgQq1bUY6it0J/1OzK0 +nFsRhFhE3tMbDzBGVjdTxUk5/g4oTl9dsa7fYjgrv/l0DR2Vo1QyiC7IOXSs4cumNCX u6KQbv7Qu3NpsTdbK7cBbBlzf1d+oqqUjLuNyWMZ+SgC99DPfv2TO48d7HSSAfsOzZyc bwErPmcZOwBhWbxbUgnxZRYaJe9HUe0ngx+Kr9XYrYIh5FhQquSKRaliTXA6IiAh6i65 b18A== X-Gm-Message-State: AIkVDXITzlSjdK7gp3fiZhJ/4LL3aZF07gAjk+wwR9hC1ZXkIzh2MbzaOC9aKMnrO8nLEw== X-Received: by 10.55.67.74 with SMTP id q71mr33797579qka.292.1485363745105; Wed, 25 Jan 2017 09:02:25 -0800 (PST) Received: from [192.168.0.3] (97-118-114-123.hlrn.qwest.net. [97.118.114.123]) by smtp.gmail.com with ESMTPSA id q5sm19288370qtc.36.2017.01.25.09.02.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 25 Jan 2017 09:02:24 -0800 (PST) From: Martin Sebor Subject: [PATCH] restore pedantic warning on flexible array members (c++/71290) To: Jason Merrill , Gcc Patch List Message-ID: Date: Wed, 25 Jan 2017 10:02:23 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.6.0 MIME-Version: 1.0 X-IsSubscribed: yes The improvements to the handling of flexible array members in C++ in GCC 6 inadvertently removed the pedantic warnings GCC used to issue for their declarations. The attached patch restores it. Martin PR c++/71290 - [6/7 Regression] 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: Adjust. * g++.dg/ext/flexarray-subst.C: Adjust. * g++.dg/ext/flexary10.C: Adjust. * g++.dg/ext/flexary11.C: Adjust. * g++.dg/ext/flexary14.C: Adjust. * g++.dg/ext/flexary16.C: Adjust. * g++.dg/ext/flexary18.C: Adjust. * g++.dg/ext/flexary19.C: Adjust. * g++.dg/ext/flexary7.C: Adjust. * g++.dg/ext/pr71290.C: New test. Index: gcc/cp/decl.c =================================================================== --- gcc/cp/decl.c (revision 244844) +++ gcc/cp/decl.c (working copy) @@ -11798,6 +11798,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); } Index: gcc/testsuite/g++.dg/ext/flexarray-mangle-2.C =================================================================== --- gcc/testsuite/g++.dg/ext/flexarray-mangle-2.C (revision 244844) +++ gcc/testsuite/g++.dg/ext/flexarray-mangle-2.C (working copy) @@ -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. Index: gcc/testsuite/g++.dg/ext/flexarray-mangle.C =================================================================== --- gcc/testsuite/g++.dg/ext/flexarray-mangle.C (revision 244844) +++ gcc/testsuite/g++.dg/ext/flexarray-mangle.C (working copy) @@ -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. Index: gcc/testsuite/g++.dg/ext/flexarray-subst.C =================================================================== --- gcc/testsuite/g++.dg/ext/flexarray-subst.C (revision 244844) +++ gcc/testsuite/g++.dg/ext/flexarray-subst.C (working copy) @@ -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; Index: gcc/testsuite/g++.dg/ext/flexary10.C =================================================================== --- gcc/testsuite/g++.dg/ext/flexary10.C (revision 244844) +++ gcc/testsuite/g++.dg/ext/flexary10.C (working copy) @@ -4,7 +4,7 @@ struct A { int n; - int a []; + int a[]; // { dg-warning "forbids flexible array member" } }; struct A foo (void) Index: gcc/testsuite/g++.dg/ext/flexary11.C =================================================================== --- gcc/testsuite/g++.dg/ext/flexary11.C (revision 244844) +++ gcc/testsuite/g++.dg/ext/flexary11.C (working copy) @@ -4,7 +4,7 @@ struct A { int n; - char a []; + char a[]; // { dg-error "forbids flexible array member" } }; void f () Index: gcc/testsuite/g++.dg/ext/flexary14.C =================================================================== --- gcc/testsuite/g++.dg/ext/flexary14.C (revision 244844) +++ gcc/testsuite/g++.dg/ext/flexary14.C (working copy) @@ -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) { Index: gcc/testsuite/g++.dg/ext/flexary16.C =================================================================== --- gcc/testsuite/g++.dg/ext/flexary16.C (revision 244844) +++ gcc/testsuite/g++.dg/ext/flexary16.C (working copy) @@ -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" } }; }; Index: gcc/testsuite/g++.dg/ext/flexary18.C =================================================================== --- gcc/testsuite/g++.dg/ext/flexary18.C (revision 244844) +++ gcc/testsuite/g++.dg/ext/flexary18.C (working copy) @@ -211,3 +211,5 @@ struct StructUnion9 { // { d } b2; // { dg-warning "invalid use" } } a2; // { dg-message "next member" } }; + +// { dg-prune-output "forbids flexible array member" } Index: gcc/testsuite/g++.dg/ext/flexary19.C =================================================================== --- gcc/testsuite/g++.dg/ext/flexary19.C (revision 244844) +++ gcc/testsuite/g++.dg/ext/flexary19.C (working copy) @@ -341,3 +341,4 @@ struct S35 typedef D D2; }; +// { dg-prune-output "forbids flexible array member" } Index: gcc/testsuite/g++.dg/ext/flexary7.C =================================================================== --- gcc/testsuite/g++.dg/ext/flexary7.C (revision 244844) +++ gcc/testsuite/g++.dg/ext/flexary7.C (working copy) @@ -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 = Index: gcc/testsuite/g++.dg/ext/pr71290.C =================================================================== --- gcc/testsuite/g++.dg/ext/pr71290.C (revision 0) +++ gcc/testsuite/g++.dg/ext/pr71290.C (working copy) @@ -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." } +};