]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c/29467 (-ansi -pedantic accepts _Bool without diagnostic)
authorMarek Polacek <polacek@redhat.com>
Thu, 1 May 2014 07:21:07 +0000 (07:21 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Thu, 1 May 2014 07:21:07 +0000 (07:21 +0000)
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.

From-SVN: r209971

gcc/c/ChangeLog
gcc/c/c-decl.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/declspec-13.c
gcc/testsuite/gcc.dg/pr29467.c [new file with mode: 0644]
gcc/testsuite/gfortran.dg/bind_c_usage_24_c.c
gcc/testsuite/gfortran.dg/c_f_pointer_logical_driver.c

index b10f6f7da9f873242e4d1dc0144334e036f5155d..e04a38d93618822263f5b71ae39b050475f5194e 100644 (file)
@@ -1,3 +1,9 @@
+2014-05-01  Marek Polacek  <polacek@redhat.com>
+
+       PR c/29467
+       * c-decl.c (declspecs_add_type): Pedwarn if boolean types are used
+       in C89 mode.
+
 2014-05-01  Marek Polacek  <polacek@redhat.com>
 
        PR c/43245
index e30876cbd1b8865b923386ddabcd966696450238..6e7c5895ec6da476ded17db4ccb8bc87ec8c639f 100644 (file)
@@ -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 "
index 619049730bd947097263dd0b5481feb310203a1a..3be6253969a7ae8d66689850df5a0d2547ad0ebc 100644 (file)
@@ -1,3 +1,13 @@
+2014-05-01  Marek Polacek  <polacek@redhat.com>
+
+       PR c/29467
+       * 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.
+
 2014-05-01  Marek Polacek  <polacek@redhat.com>
 
        PR c/43245
index a325c0d883196b7c49cfc80972b879e7ffef9877..3b4e315ef356f9a59159a8f0ac06bfeb91258205 100644 (file)
@@ -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 a/gcc/testsuite/gcc.dg/pr29467.c b/gcc/testsuite/gcc.dg/pr29467.c
new file mode 100644 (file)
index 0000000..eaf09c2
--- /dev/null
@@ -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" } */
+}
index ffc90b728b5e1f1f241da8f20ba397d87d35ceda..65754f3415d7ba3a43afc17fcd565375969e31c7 100644 (file)
@@ -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)
index e3044c92e436e11ef9c6599b2780ca5d849f27c1..a05449dc1810d5d2e2116b819335a82d3dfa8921 100644 (file)
@@ -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);