diff mbox

[C++] Fix PR63366: __complex not equivalent to __complex double in C++

Message ID 000001cfdbb7$974ce1d0$c5e6a570$@arm.com
State New
Headers show

Commit Message

Thomas Preud'homme Sept. 29, 2014, 7:32 a.m. UTC
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  <thomas.preudhomme@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  <thomas.preudhomme@arm.com>

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




Is this ok for trunk?

Best regards,

Thomas Preud'homme

Comments

Thomas Preud'homme Sept. 30, 2014, 4:35 a.m. UTC | #1
> From: gcc-patches-owner@gcc.gnu.org [mailto:gcc-patches-
> owner@gcc.gnu.org] On Behalf Of Thomas Preud'homme
> Sent: Monday, September 29, 2014 3:33 PM
> ChangeLog are as follows:
> 
> *** gcc/cp/ChangeLog ***
> 
> 2014-09-26  Thomas Preud'homme  <thomas.preudhomme@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  <thomas.preudhomme@arm.com>
> 
> 	* 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  <thomas.preudhomme@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  <thomas.preudhomme@arm.com>

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

Best regards,

Thomas
Thomas Preud'homme Oct. 9, 2014, 9:24 a.m. UTC | #2
Ping?

> -----Original Message-----
> From: gcc-patches-owner@gcc.gnu.org [mailto:gcc-patches-
> owner@gcc.gnu.org] On Behalf Of Thomas Preud'homme
> Sent: Monday, September 29, 2014 3:33 PM
> To: gcc-patches@gcc.gnu.org
> Subject: [PATCH, C++] Fix PR63366: __complex not equivalent to
> __complex double in C++
> 
> 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  <thomas.preudhomme@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  <thomas.preudhomme@arm.com>
> 
>	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 Oct. 9, 2014, 1:25 p.m. UTC | #3
On 10/09/2014 05:24 AM, Thomas Preud'homme wrote:
>>                    "ISO C++ forbids declaration of %qs with no type", name);
>>
>>         type = integer_type_node;
>> +      defaulted_int = 1;

I would think we want to handle this up in the existing defaulted_int block:

>   /* 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))

>> +  return typeid (__complex) != typeid (__complex double);

Don't we want this to be '=='?

Jason
Nathan Sidwell Oct. 9, 2014, 1:30 p.m. UTC | #4
On 10/09/14 09:25, Jason Merrill wrote:
> On 10/09/2014 05:24 AM, Thomas Preud'homme wrote:
>>>                    "ISO C++ forbids declaration of %qs with no type", name);
>>>
>>>         type = integer_type_node;
>>> +      defaulted_int = 1;
>
> I would think we want to handle this up in the existing defaulted_int block:
my thought was to at least put it next to the explicit_int = -1 above.

>>   /* 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))
>
>>> +  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
Jason Merrill Oct. 9, 2014, 1:32 p.m. UTC | #5
On 10/09/2014 09:30 AM, Nathan Sidwell wrote:
>>>> +  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
diff mbox

Patch

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);
+}