From patchwork Tue Apr 29 21:18:27 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Polacek X-Patchwork-Id: 343991 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 8B1341400E7 for ; Wed, 30 Apr 2014 07:18:43 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:mime-version:content-type; q=dns; s=default; b=TdbGpL4vSY82Xi0i9PEKe5nZUvO/gEUgpKZXx+e9rl2NBJv5ff a9oirJdp05eag/Ikxzsz6a4MUyhtGriyAVza873fPrym/YA86RTFO9Ll1QlhXUv7 FQo9T2O6GPQF1+mW/x05t8pNu6RQ+JqJtG8HIXk8dqaGhq8o2C3a7LXoA= 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:date :from:to:cc:subject:message-id:mime-version:content-type; s= default; bh=gFAL0TcgKTJpzSyfH3bTclpHRnw=; b=nND/yU+XoUq4rqkn2ptq 5+re5w18J4iY8O3uKKnGMrUwe8Cfm+QsPTlJb9UPqdKFjGhL3KghLVsCO7ckSNSB jTo9aVo780ztWw5fWmH5sQC/YwENSBKMwUf/MPuZQHxkdXK3WWiwnLtoYk+6fI/U Nvikk0h/vb5y8l5U6RRVf/8= Received: (qmail 3030 invoked by alias); 29 Apr 2014 21:18:36 -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 3015 invoked by uid 89); 29 Apr 2014 21:18:35 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.1 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 29 Apr 2014 21:18:34 +0000 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s3TLIVDW001710 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 29 Apr 2014 17:18:31 -0400 Received: from redhat.com (ovpn-116-53.ams2.redhat.com [10.36.116.53]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s3TLISUi016755 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=NO); Tue, 29 Apr 2014 17:18:30 -0400 Date: Tue, 29 Apr 2014 23:18:27 +0200 From: Marek Polacek To: GCC Patches Cc: "Joseph S. Myers" Subject: [C PATCH] Warn about booleans in C89 mode (PR c/29467) Message-ID: <20140429211827.GD11802@redhat.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) Boolean types were introduced with the advent of C99, which means we should pedwarn when _Bool is used in ansi/c89/c90/iso9899:1990 mode with -Wpedantic, similarly what we do for _Complex. We don't warn for system headers, so it's possible to include and then use bool. I made use of that to fix some fortran tests (it's not possible to add dg-options, since these tests we're using C files via dg-additional-source). Regtested/bootstrapped on x86_64-linux, ok for trunk? 2014-04-29 Marek Polacek PR c/29467 * c-decl.c (declspecs_add_type): Pedwarn if boolean types are used in C89 mode. * gcc.dg/pr29467.c: New test. * gcc.dg/declspec-13.c: Renumber some dg-warnings. Add dg-warnings about boolean types. * gfortran.dg/bind_c_usage_24_c.c: Include . Change _Bool to bool. * gfortran.dg/c_f_pointer_logical_driver.c: Change _Bool to bool. Marek diff --git gcc/c/c-decl.c gcc/c/c-decl.c index e30876c..6e7c589 100644 --- gcc/c/c-decl.c +++ gcc/c/c-decl.c @@ -9564,6 +9564,9 @@ declspecs_add_type (location_t loc, struct c_declspecs *specs, } return specs; case RID_BOOL: + if (!flag_isoc99 && !in_system_header_at (loc)) + pedwarn (loc, OPT_Wpedantic, + "ISO C90 does not support boolean types"); if (specs->long_p) error_at (loc, ("both % and %<_Bool%> in " diff --git gcc/testsuite/gcc.dg/declspec-13.c gcc/testsuite/gcc.dg/declspec-13.c index a325c0d..3b4e315 100644 --- gcc/testsuite/gcc.dg/declspec-13.c +++ gcc/testsuite/gcc.dg/declspec-13.c @@ -36,43 +36,53 @@ long double long x3; /* { dg-error "both 'long long' and 'double' in declaration short long x4; /* { dg-error "both 'long' and 'short' in declaration specifiers" } */ void long x5; /* { dg-error "both 'long' and 'void' in declaration specifiers" } */ _Bool long x6; /* { dg-error "both 'long' and '_Bool' in declaration specifiers" } */ +/* { dg-warning "ISO C90 does not support boolean types" "C90" { target *-*-* } 38 } */ char long x7; /* { dg-error "both 'long' and 'char' in declaration specifiers" } */ float long x8; /* { dg-error "both 'long' and 'float' in declaration specifiers" } */ long short x9; /* { dg-error "both 'long' and 'short' in declaration specifiers" } */ void short x10; /* { dg-error "both 'short' and 'void' in declaration specifiers" } */ _Bool short x11; /* { dg-error "both 'short' and '_Bool' in declaration specifiers" } */ +/* { dg-warning "ISO C90 does not support boolean types" "C90" { target *-*-* } 44 } */ char short x12; /* { dg-error "both 'short' and 'char' in declaration specifiers" } */ float short x13; /* { dg-error "both 'short' and 'float' in declaration specifiers" } */ double short x14; /* { dg-error "both 'short' and 'double' in declaration specifiers" } */ unsigned signed x15; /* { dg-error "both 'signed' and 'unsigned' in declaration specifiers" } */ void signed x16; /* { dg-error "both 'signed' and 'void' in declaration specifiers" } */ _Bool signed x17; /* { dg-error "both 'signed' and '_Bool' in declaration specifiers" } */ +/* { dg-warning "ISO C90 does not support boolean types" "C90" { target *-*-* } 51 } */ float signed x18; /* { dg-error "both 'signed' and 'float' in declaration specifiers" } */ double signed x19; /* { dg-error "both 'signed' and 'double' in declaration specifiers" } */ signed unsigned x20; /* { dg-error "both 'signed' and 'unsigned' in declaration specifiers" } */ void unsigned x21; /* { dg-error "both 'unsigned' and 'void' in declaration specifiers" } */ _Bool unsigned x22; /* { dg-error "both 'unsigned' and '_Bool' in declaration specifiers" } */ +/* { dg-warning "ISO C90 does not support boolean types" "C90" { target *-*-* } 57 } */ float unsigned x23; /* { dg-error "both 'unsigned' and 'float' in declaration specifiers" } */ double unsigned x24; /* { dg-error "both 'unsigned' and 'double' in declaration specifiers" } */ void _Complex x25; /* { dg-error "both 'complex' and 'void' in declaration specifiers" } */ -/* { dg-warning "ISO C90 does not support complex types" "C90" { target *-*-* } 57 } */ +/* { dg-warning "ISO C90 does not support complex types" "C90" { target *-*-* } 61 } */ _Bool _Complex x26; /* { dg-error "both 'complex' and '_Bool' in declaration specifiers" } */ -/* { dg-warning "ISO C90 does not support complex types" "C90" { target *-*-* } 59 } */ +/* { dg-warning "ISO C90 does not support complex types" "C90" { target *-*-* } 63 } */ +/* { dg-warning "ISO C90 does not support boolean types" "C90" { target *-*-* } 63 } */ long void x27; /* { dg-error "both 'long' and 'void' in declaration specifiers" } */ short void x28; /* { dg-error "both 'short' and 'void' in declaration specifiers" } */ signed void x29; /* { dg-error "both 'signed' and 'void' in declaration specifiers" } */ unsigned void x30; /* { dg-error "both 'unsigned' and 'void' in declaration specifiers" } */ _Complex void x31; /* { dg-error "both 'complex' and 'void' in declaration specifiers" } */ -/* { dg-warning "ISO C90 does not support complex types" "C90" { target *-*-* } 66 } */ -/* { dg-warning "ISO C does not support plain 'complex' meaning 'double complex'" "complex" { target *-*-* } 66 } */ +/* { dg-warning "ISO C90 does not support complex types" "C90" { target *-*-* } 71 } */ +/* { dg-warning "ISO C does not support plain 'complex' meaning 'double complex'" "complex" { target *-*-* } 71 } */ long _Bool x32; /* { dg-error "both 'long' and '_Bool' in declaration specifiers" } */ +/* { dg-warning "ISO C90 does not support boolean types" "C90" { target *-*-* } 74 } */ short _Bool x33; /* { dg-error "both 'short' and '_Bool' in declaration specifiers" } */ +/* { dg-warning "ISO C90 does not support boolean types" "C90" { target *-*-* } 76 } */ signed _Bool x34; /* { dg-error "both 'signed' and '_Bool' in declaration specifiers" } */ +/* { dg-warning "ISO C90 does not support boolean types" "C90" { target *-*-* } 78 } */ unsigned _Bool x35; /* { dg-error "both 'unsigned' and '_Bool' in declaration specifiers" } */ +/* { dg-warning "ISO C90 does not support boolean types" "C90" { target *-*-* } 80 } */ _Complex _Bool x36; /* { dg-error "both 'complex' and '_Bool' in declaration specifiers" } */ -/* { dg-warning "ISO C90 does not support complex types" "C90" { target *-*-* } 73 } */ -/* { dg-warning "ISO C does not support plain 'complex' meaning 'double complex'" "complex" { target *-*-* } 73 } */ +/* { dg-warning "ISO C90 does not support complex types" "C90" { target *-*-* } 82 } */ +/* { dg-warning "ISO C90 does not support boolean types" "C90" { target *-*-* } 82 } */ +/* { dg-warning "ISO C does not support plain 'complex' meaning 'double complex'" "complex" { target *-*-* } 82 } */ long char x37; /* { dg-error "both 'long' and 'char' in declaration specifiers" } */ short char x38; /* { dg-error "both 'short' and 'char' in declaration specifiers" } */ long float x39; /* { dg-error "both 'long' and 'float' in declaration specifiers" } */ @@ -80,7 +90,7 @@ short float x40; /* { dg-error "both 'short' and 'float' in declaration specifie signed float x41; /* { dg-error "both 'signed' and 'float' in declaration specifiers" } */ unsigned float x42; /* { dg-error "both 'unsigned' and 'float' in declaration specifiers" } */ long long double x43; /* { dg-error "both 'long long' and 'double' in declaration specifiers" } */ -/* { dg-warning "ISO C90 does not support 'long long'" "C90" { target *-*-* } 82 } */ +/* { dg-warning "ISO C90 does not support 'long long'" "C90" { target *-*-* } 92 } */ short double x44; /* { dg-error "both 'short' and 'double' in declaration specifiers" } */ signed double x45; /* { dg-error "both 'signed' and 'double' in declaration specifiers" } */ unsigned double x46; /* { dg-error "both 'unsigned' and 'double' in declaration specifiers" } */ diff --git gcc/testsuite/gcc.dg/pr29467.c gcc/testsuite/gcc.dg/pr29467.c index e69de29..eaf09c2 100644 --- gcc/testsuite/gcc.dg/pr29467.c +++ gcc/testsuite/gcc.dg/pr29467.c @@ -0,0 +1,13 @@ +/* PR c/29467 */ +/* { dg-do compile } */ +/* { dg-options "-std=c89 -Wpedantic" } */ + +_Bool b; /* { dg-warning "ISO C90 does not support boolean types" } */ +typedef _Bool B; /* { dg-warning "ISO C90 does not support boolean types" } */ +static _Bool sb; /* { dg-warning "ISO C90 does not support boolean types" } */ + +_Bool /* { dg-warning "ISO C90 does not support boolean types" } */ +foo (_Bool bp) /* { dg-warning "ISO C90 does not support boolean types" } */ +{ + _Bool bl; /* { dg-warning "ISO C90 does not support boolean types" } */ +} diff --git gcc/testsuite/gfortran.dg/bind_c_usage_24_c.c gcc/testsuite/gfortran.dg/bind_c_usage_24_c.c index ffc90b7..65754f3 100644 --- gcc/testsuite/gfortran.dg/bind_c_usage_24_c.c +++ gcc/testsuite/gfortran.dg/bind_c_usage_24_c.c @@ -1,11 +1,12 @@ /* Compiled and linked by bind_c.f90. */ #include +#include -void subtest (_Bool, int *); +void subtest (bool, int *); void -c_proc (_Bool present, int *val) +c_proc (bool present, int *val) { int val2; if (!present && val) diff --git gcc/testsuite/gfortran.dg/c_f_pointer_logical_driver.c gcc/testsuite/gfortran.dg/c_f_pointer_logical_driver.c index e3044c9..a05449d 100644 --- gcc/testsuite/gfortran.dg/c_f_pointer_logical_driver.c +++ gcc/testsuite/gfortran.dg/c_f_pointer_logical_driver.c @@ -4,13 +4,13 @@ #define NUM_ELEMS 10 -void test_scalar(_Bool *my_c_bool_ptr); -void test_array(_Bool *my_bool_array, int num_elems); +void test_scalar(bool *my_c_bool_ptr); +void test_array(bool *my_bool_array, int num_elems); int main(int argc, char **argv) { - _Bool my_bool = true; - _Bool my_bool_array[NUM_ELEMS]; + bool my_bool = true; + bool my_bool_array[NUM_ELEMS]; int i; test_scalar(&my_bool);