]> gcc.gnu.org Git - gcc.git/commitdiff
c-decl.c (grokdeclarator): Don't give a warning about defaulting to int for plain...
authorJoseph Myers <jsm28@cam.ac.uk>
Sun, 17 Sep 2000 19:39:56 +0000 (20:39 +0100)
committerJoseph Myers <jsm28@gcc.gnu.org>
Sun, 17 Sep 2000 19:39:56 +0000 (20:39 +0100)
* c-decl.c (grokdeclarator): Don't give a warning about defaulting
to int for plain complex which defaults to complex double.  Do
warn about defaulting to complex double if pedantic.  Warn about
complex integer types if pedantic.  Warn about complex types if
pedantic and not in C99 mode.
* c-typeck.c (build_unary_op): If pedantic, warn about use of ~
for complex conjugation.

testsuite:
* gcc.dg/c90-complex-1.c, gcc.dg/c99-complex-1.c: New tests.

From-SVN: r36478

gcc/ChangeLog
gcc/c-decl.c
gcc/c-typeck.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/c90-complex-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/c99-complex-1.c [new file with mode: 0644]

index 98e82ada635b81f98b1bb2f07204425dba4f53c0..2d08c82d4e235e3363564832bacf91798e6c6d5a 100644 (file)
@@ -1,3 +1,13 @@
+2000-09-17  Joseph S. Myers  <jsm28@cam.ac.uk>
+
+       * c-decl.c (grokdeclarator): Don't give a warning about defaulting
+       to int for plain complex which defaults to complex double.  Do
+       warn about defaulting to complex double if pedantic.  Warn about
+       complex integer types if pedantic.  Warn about complex types if
+       pedantic and not in C99 mode.
+       * c-typeck.c (build_unary_op): If pedantic, warn about use of ~
+       for complex conjugation.
+
 2000-09-17  Joseph S. Myers  <jsm28@cam.ac.uk>
 
        * contrib.texi: Update my entry.
index 1de1f9748c359af0ee6970feedb65b3115f814d6..8287eefb2e466cccedb78b6e783be09deadc1edc 100644 (file)
@@ -4078,7 +4078,8 @@ grokdeclarator (declarator, declspecs, decl_context, initialized)
     {
       if ((! (specbits & ((1 << (int) RID_LONG) | (1 << (int) RID_SHORT)
                          | (1 << (int) RID_SIGNED)
-                         | (1 << (int) RID_UNSIGNED))))
+                         | (1 << (int) RID_UNSIGNED)
+                         | (1 << (int) RID_COMPLEX))))
          /* Don't warn about typedef foo = bar.  */
          && ! (specbits & (1 << (int) RID_TYPEDEF) && initialized)
          && ! in_system_header)
@@ -4209,6 +4210,8 @@ grokdeclarator (declarator, declspecs, decl_context, initialized)
 
   if (specbits & 1 << (int) RID_COMPLEX)
     {
+      if (pedantic && !flag_isoc99)
+       pedwarn ("ISO C89 does not support complex types");
       /* If we just have "complex", it is equivalent to
         "complex double", but if any modifiers at all are specified it is
         the complex form of TYPE.  E.g, "complex short" is
@@ -4218,9 +4221,17 @@ grokdeclarator (declarator, declspecs, decl_context, initialized)
          && ! (specbits & ((1 << (int) RID_LONG) | (1 << (int) RID_SHORT)
                            | (1 << (int) RID_SIGNED)
                            | (1 << (int) RID_UNSIGNED))))
-       type = complex_double_type_node;
+       {
+         if (pedantic)
+           pedwarn ("ISO C does not support plain `complex' meaning `double complex'");
+         type = complex_double_type_node;
+       }
       else if (type == integer_type_node)
-       type = complex_integer_type_node;
+       {
+         if (pedantic)
+           pedwarn ("ISO C does not support complex integer types");
+         type = complex_integer_type_node;
+       }
       else if (type == float_type_node)
        type = complex_float_type_node;
       else if (type == double_type_node)
@@ -4228,7 +4239,11 @@ grokdeclarator (declarator, declspecs, decl_context, initialized)
       else if (type == long_double_type_node)
        type = complex_long_double_type_node;
       else
-       type = build_complex_type (type);
+       {
+         if (pedantic)
+           pedwarn ("ISO C does not support complex integer types");
+         type = build_complex_type (type);
+       }
     }
 
   /* Figure out the type qualifiers for the declaration.  There are
index f4b42b991a50793ed1bd4cde343abe373708a835..75fb57a6b6179d124cb0b36bd30c33e49db8c5f2 100644 (file)
@@ -2807,6 +2807,8 @@ build_unary_op (code, xarg, noconvert)
       if (typecode == COMPLEX_TYPE)
        {
          code = CONJ_EXPR;
+         if (pedantic)
+           pedwarn ("ISO C does not support `~' for complex conjugation");
          if (!noconvert)
            arg = default_conversion (arg);
        }
index 3e847d85565025545f065fe3c424d267069cb53c..0362ad7f2f62cb07a43f9d04c4cc713417c45882 100644 (file)
@@ -1,3 +1,7 @@
+2000-09-17  Joseph S. Myers  <jsm28@cam.ac.uk>
+
+       * gcc.dg/c90-complex-1.c, gcc.dg/c99-complex-1.c: New tests.
+
 2000-09-17  Greg McGary  <greg@mcgary.org>
 
        * gcc.c-torture/execute/20000917-1.c: New test.
diff --git a/gcc/testsuite/gcc.dg/c90-complex-1.c b/gcc/testsuite/gcc.dg/c90-complex-1.c
new file mode 100644 (file)
index 0000000..b65fc68
--- /dev/null
@@ -0,0 +1,7 @@
+/* Test for _Complex: in C99 only.  */
+/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
+/* { dg-do compile } */
+/* { dg-options "-std=iso9899:1990 -pedantic-errors" } */
+
+_Complex double foo; /* { dg-bogus "warning" "warning in place of error" } */
+/* { dg-error "C" "_Complex not in C90" { target *-*-* } 6 } */
diff --git a/gcc/testsuite/gcc.dg/c99-complex-1.c b/gcc/testsuite/gcc.dg/c99-complex-1.c
new file mode 100644 (file)
index 0000000..2e1ba7d
--- /dev/null
@@ -0,0 +1,33 @@
+/* Test for _Complex: in C99 only.  A few basic tests.  */
+/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
+/* { dg-do compile } */
+/* { dg-options "-std=iso9899:1999 -pedantic-errors" } */
+
+/* Test _Complex allowed on floating types.  */
+
+float _Complex a;
+_Complex float b;
+double _Complex c;
+_Complex double d;
+long double _Complex e;
+_Complex long double f;
+
+/* Plain `_Complex' for complex double is a GNU extension.  */
+_Complex g; /* { dg-bogus "warning" "warning in place of error" } */
+/* { dg-error "plain" "plain _Complex" { target *-*-* } 16 } */
+
+/* Complex integer types are GNU extensions.  */
+_Complex int h; /* { dg-bogus "warning" "warning in place of error" } */
+/* { dg-error "complex integer" "_Complex int" { target *-*-* } 20 } */
+_Complex long i; /* { dg-bogus "warning" "warning in place of error" } */
+/* { dg-error "complex integer" "_Complex long" { target *-*-* } 22 } */
+
+/* Use of ~ for complex conjugation is a GNU extension, but a constraint
+   violation (6.5.3.3p1) in C99.
+*/
+_Complex double
+foo (_Complex double z)
+{
+  return ~z; /* { dg-bogus "warning" "warning in place of error" } */
+  /* { dg-error "complex conj" "~ for conjugation" { target *-*-* } 31 } */
+}
This page took 0.095241 seconds and 5 git commands to generate.