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
<stdbool.h> 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  <pola...@redhat.com>

        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 <stdbool.h>.  Change _Bool
        to bool.
        * gfortran.dg/c_f_pointer_logical_driver.c: Change _Bool to bool.

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 %<long%> 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 <stdlib.h>
+#include <stdbool.h>
 
-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);

        Marek

Reply via email to