Bug 50992 - Wconversion does not handle complex type conversions
Summary: Wconversion does not handle complex type conversions
Status: RESOLVED DUPLICATE of bug 48956
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 4.6.2
: P3 enhancement
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2011-11-04 14:38 UTC by Alexander
Modified: 2012-03-24 19:14 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2011-11-04 00:00:00


Attachments
NULL (136 bytes, application/octet-stream)
2011-11-04 14:59 UTC, Alexander
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Alexander 2011-11-04 14:38:12 UTC
gcc does not see an obvious error.
Code:
  complex double Z;
  abs(Z);
abs() even not a fabsl()! And this code work!
Comment 1 Paolo Carlini 2011-11-04 14:45:39 UTC
Please provide a *self-contained*, minimal testcase. Thanks,
Comment 2 Alexander 2011-11-04 14:59:53 UTC
Created attachment 25714 [details]
NULL

I right now noticed that abs() just return real part of complex number.
Comment 3 Manuel López-Ibáñez 2011-11-04 15:08:09 UTC
#include <complex.h>

extern int abs(int);
int foo(void) {
  complex double Z = 0.1 + 0.2I;
  return abs(Z);
}

GCC says nothing with -Wall -Wextra -Wconversion, because c-common.c:conversion_warnings() does not handle complex variables.

Clang:

test.c:6:14: warning: implicit conversion discards imaginary component: '_Complex double' to 'int' [-Wconversion]
  return abs(Z);
         ~~~ ^
1 warning generated.
Comment 4 Alexander 2011-11-04 15:12:13 UTC
(In reply to comment #3)
> #include <complex.h>
> 
> extern int abs(int);
> int foo(void) {
>   complex double Z = 0.1 + 0.2I;
>   return abs(Z);
> }
> 
> GCC says nothing with -Wall -Wextra -Wconversion, because
> c-common.c:conversion_warnings() does not handle complex variables.
> 
> Clang:
> 
> test.c:6:14: warning: implicit conversion discards imaginary component:
> '_Complex double' to 'int' [-Wconversion]
>   return abs(Z);
>          ~~~ ^
> 1 warning generated.

I noticed. So what? Why was this done?
Comment 5 Manuel López-Ibáñez 2011-11-04 15:18:23 UTC
(In reply to comment #4)
> 
> I noticed. So what? Why was this done?

It is just not implemented yet. Someone needs to want it enough to implement it.
Comment 6 Alexander 2011-11-04 15:22:53 UTC
(In reply to comment #5)
> (In reply to comment #4)
> > 
> > I noticed. So what? Why was this done?
> 
> It is just not implemented yet. Someone needs to want it enough to implement
> it.

May be people just not see that thing, like me(I noticed this only after a couple of hours).
Comment 7 Manuel López-Ibáñez 2012-03-24 19:14:49 UTC
It seems someone did a patch in a different bug report, but didn't submit it for approval.

*** This bug has been marked as a duplicate of bug 48956 ***