> From: Jason Merrill [mailto:ja...@redhat.com]
> Sent: Wednesday, October 29, 2014 4:43 PM
> 
> Since this is a GNU extension, I think we want to be compatible with the
> C front end, which has
> 
> >       else if (specs->complex_p)
> >         {
> >           specs->typespec_word = cts_double;
> >           pedwarn (specs->locations[cdw_complex], OPT_Wpedantic,
> >                    "ISO C does not support plain %<complex%> meaning "
> >                    "%<double complex%>");
> >         }
> 
> right after the code that parallels the block I mentioned in my earlier
> mail.

What about the following patch?

diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index d26a432..d3ab81c 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -9158,11 +9158,23 @@ grokdeclarator (const cp_declarator *declarator,
     }
   /* No type at all: default to `int', and set DEFAULTED_INT
      because it was not a user-defined typedef.  */
-  if (type == NULL_TREE && (signed_p || unsigned_p || long_p || short_p))
+  if (type == NULL_TREE)
     {
-      /* These imply 'int'.  */
-      type = integer_type_node;
-      defaulted_int = 1;
+      if (signed_p || unsigned_p || long_p || short_p)
+       {
+         /* These imply 'int'.  */
+         type = integer_type_node;
+         defaulted_int = 1;
+       }
+      /* If we just have "complex", it is equivalent to "complex double".  */
+      else if (!longlong && !explicit_int128
+              && decl_spec_seq_has_spec_p (declspecs, ds_complex))
+       {
+         type = double_type_node;
+         pedwarn (declspecs->locations[ds_complex], OPT_Wpedantic,
+                  "ISO C++ does not support plain %<complex%> meaning "
+                  "%<double complex%>");
+       }
     }
   /* Gather flags.  */
   explicit_int = declspecs->explicit_int_p;
@@ -9345,13 +9357,8 @@ grokdeclarator (const cp_declarator *declarator,
     {
       if (TREE_CODE (type) != INTEGER_TYPE && TREE_CODE (type) != REAL_TYPE)
        error ("complex invalid for %qs", name);
-      /* 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
-        "complex short int".  */
-      else if (defaulted_int && ! longlong && ! explicit_int128
-              && ! (long_p || short_p || signed_p || unsigned_p))
-       type = complex_double_type_node;
+      /* If a modifier is specified, the resulting complex is the complex
+        form of TYPE.  E.g, "complex short" is "complex short int".  */
       else if (type == integer_type_node)
        type = complex_integer_type_node;
       else if (type == float_type_node)
diff --git a/gcc/testsuite/g++.dg/torture/pr63366.C 
b/gcc/testsuite/g++.dg/torture/pr63366.C
new file mode 100644
index 0000000..f089123
--- /dev/null
+++ b/gcc/testsuite/g++.dg/torture/pr63366.C
@@ -0,0 +1,10 @@
+// { dg-do run }
+// { dg-options "-pedantic" }
+
+#include <typeinfo>
+
+int
+main (void)
+{
+  return typeid (__complex) != typeid (__complex double); /* { dg-warning "ISO 
C\\+\\+ does not support plain 'complex' meaning 'double complex'" } */
+}


ChangeLog entries would be as follows:

*** cp/ChangeLog ***

2014-11-03  Thomas Preud'homme  <thomas.preudho...@arm.com>

        PR C++/63366
        * decl.c (grokdeclarator): Set default for complex alone to complex
        double and issue a pedantic warn for it.

*** testsuite/ChangeLog ***

2014-11-03  Thomas Preud'homme  <thomas.preudho...@arm.com>

        PR C++/63366
        * g++.dg/torture/pr63366.C: New test.


Ok for trunk?

Best regards,

Thomas 




Reply via email to