Discussion:
[PATCH, C++] Fix PR63366: __complex not equivalent to __complex double in C++
Thomas Preud'homme
2014-09-29 07:32:55 UTC
Permalink
According to a comment in grokdeclarator in file gcc/cp/decl.c:

/* 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". */

Yet, __complex is equivalent to __complex int as shows the following testcase:

#include <typeinfo>

int
main (void)
{
return typeid (__complex) != typeid (__complex int);
}

The following patch fix the problem.


ChangeLog are as follows:

*** gcc/cp/ChangeLog ***

2014-09-26 Thomas Preud'homme <***@arm.com>

* decl.c (grokdeclarator): Set defaulted_int when defaulting to int
because type is null.

*** gcc/testsuite/ChangeLog ***

2014-10-26 Thomas Preud'homme <***@arm.com>

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


diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index d26a432..449efdf 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -9212,6 +9212,7 @@ grokdeclarator (const cp_declarator *declarator,
"ISO C++ forbids declaration of %qs with no type", name);

type = integer_type_node;
+ defaulted_int = 1;
}

ctype = NULL_TREE;
diff --git a/gcc/testsuite/g++.dg/torture/pr63366.C b/gcc/testsuite/g++.dg/torture/pr63366.C
new file mode 100644
index 0000000..af59b98
--- /dev/null
+++ b/gcc/testsuite/g++.dg/torture/pr63366.C
@@ -0,0 +1,11 @@
+// { dg-do run }
+// { dg-options "-fpermissive" }
+// { dg-prune-output "ISO C\\+\\+ forbids declaration of 'type name' with no type" }
+
+#include <typeinfo>
+
+int
+main (void)
+{
+ return typeid (__complex) != typeid (__complex double);
+}


Is this ok for trunk?

Best regards,

Thomas Preud'homme
Thomas Preud'homme
2014-09-30 04:35:40 UTC
Permalink
Sent: Monday, September 29, 2014 3:33 PM
*** gcc/cp/ChangeLog ***
* decl.c (grokdeclarator): Set defaulted_int when defaulting to int
because type is null.
*** gcc/testsuite/ChangeLog ***
* g++.dg/torture/pr63366.C: New test.
Forgot the PR info. Here are the right ChangeLog:

*** gcc/cp/ChangeLog ***

2014-09-26 Thomas Preud'homme <***@arm.com>

PR C++/63366
* decl.c (grokdeclarator): Set defaulted_int when defaulting to int
because type is null.

*** gcc/testsuite/ChangeLog ***

2014-10-26 Thomas Preud'homme <***@arm.com>

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

Best regards,

Thomas
Thomas Preud'homme
2014-10-09 09:24:00 UTC
Permalink
Ping?
-----Original Message-----
Sent: Monday, September 29, 2014 3:33 PM
Subject: [PATCH, C++] Fix PR63366: __complex not equivalent to
__complex double in C++
/* 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". */
#include <typeinfo>
int
main (void)
{
return typeid (__complex) != typeid (__complex int);
}
The following patch fix the problem.
*** gcc/cp/ChangeLog ***
PR C++/63366
* decl.c (grokdeclarator): Set defaulted_int when defaulting to int
because type is null.
*** gcc/testsuite/ChangeLog ***
PR C++/63366
* g++.dg/torture/pr63366.C: New test.
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index d26a432..449efdf 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -9212,6 +9212,7 @@ grokdeclarator (const cp_declarator *declarator,
"ISO C++ forbids declaration of %qs with no type", name);
type = integer_type_node;
+ defaulted_int = 1;
}
ctype = NULL_TREE;
diff --git a/gcc/testsuite/g++.dg/torture/pr63366.C
b/gcc/testsuite/g++.dg/torture/pr63366.C
new file mode 100644
index 0000000..af59b98
--- /dev/null
+++ b/gcc/testsuite/g++.dg/torture/pr63366.C
@@ -0,0 +1,11 @@
+// { dg-do run }
+// { dg-options "-fpermissive" }
+// { dg-prune-output "ISO C\\+\\+ forbids declaration of 'type name' with no type" }
+
+#include <typeinfo>
+
+int
+main (void)
+{
+ return typeid (__complex) != typeid (__complex double);
+}
Is this ok for trunk?
Best regards,
Thomas Preud'homme
Jason Merrill
2014-10-09 13:25:23 UTC
Permalink
Post by Thomas Preud'homme
"ISO C++ forbids declaration of %qs with no type", name);
type = integer_type_node;
+ defaulted_int = 1;
/* 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))
Post by Thomas Preud'homme
+ return typeid (__complex) != typeid (__complex double);
Don't we want this to be '=='?

Jason
Nathan Sidwell
2014-10-09 13:30:11 UTC
Permalink
Post by Jason Merrill
Post by Thomas Preud'homme
"ISO C++ forbids declaration of %qs with no type", name);
type = integer_type_node;
+ defaulted_int = 1;
my thought was to at least put it next to the explicit_int = -1 above.
Post by Jason Merrill
/* 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))
Post by Thomas Preud'homme
+ return typeid (__complex) != typeid (__complex double);
Don't we want this to be '=='?
I think it wants to check for _complex being __complex double, not not being
_complex int (other failure modes exist!)

nathan
--
Nathan Sidwell
Jason Merrill
2014-10-09 13:32:46 UTC
Permalink
Post by Nathan Sidwell
Post by Jason Merrill
Post by Thomas Preud'homme
+ return typeid (__complex) != typeid (__complex double);
Don't we want this to be '=='?
I think it wants to check for _complex being __complex double, not not
being _complex int (other failure modes exist!)
Right, I was forgetting about returning nonzero for failure.

Jason

Loading...