public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/54234] New: -Wconversion or -Wconversion-extra should warn for CMPLX(dp,dp)
@ 2012-08-12 14:26 burnus at gcc dot gnu.org
2012-08-12 16:12 ` [Bug fortran/54234] " kargl at gcc dot gnu.org
` (5 more replies)
0 siblings, 6 replies; 7+ messages in thread
From: burnus at gcc dot gnu.org @ 2012-08-12 14:26 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54234
Bug #: 54234
Summary: -Wconversion or -Wconversion-extra should warn for
CMPLX(dp,dp)
Classification: Unclassified
Product: gcc
Version: 4.8.0
Status: UNCONFIRMED
Keywords: diagnostic
Severity: normal
Priority: P3
Component: fortran
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: burnus@gcc.gnu.org
When calling CMPLX with non-default-kind arguments, the compiler should warn
about the conversion, i.e. for
CMPLX (0.1_dp, 0.1_dp)
as the expression is complex(4) while the arguments are REALs with kind=8.
There should be no warning for cmplx (complex number).
Longer example – compile with -Wconversion -Wconversion-extra. Again, I'd
expect a warning for the CMPLX:
module fft_mod
implicit none
integer, parameter :: dp=selected_real_kind(15,300)
real(kind=dp), parameter :: pi=3.141592653589793238460
contains
subroutine test
integer :: x
x = int (abs (cmplx(2.3_dp,0.1_dp)))
end subroutine test
end module fft_mod
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug fortran/54234] -Wconversion or -Wconversion-extra should warn for CMPLX(dp,dp)
2012-08-12 14:26 [Bug fortran/54234] New: -Wconversion or -Wconversion-extra should warn for CMPLX(dp,dp) burnus at gcc dot gnu.org
@ 2012-08-12 16:12 ` kargl at gcc dot gnu.org
2012-08-12 16:23 ` tkoenig at gcc dot gnu.org
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: kargl at gcc dot gnu.org @ 2012-08-12 16:12 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54234
kargl at gcc dot gnu.org changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |kargl at gcc dot gnu.org
--- Comment #1 from kargl at gcc dot gnu.org 2012-08-12 16:12:09 UTC ---
I believe that a warning is not necessary and
in fact should not be issued. The Fortran
standard explicitly states that CMPLX returns
a complex number with default real kind if the
KIND= optional argument is not used.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug fortran/54234] -Wconversion or -Wconversion-extra should warn for CMPLX(dp,dp)
2012-08-12 14:26 [Bug fortran/54234] New: -Wconversion or -Wconversion-extra should warn for CMPLX(dp,dp) burnus at gcc dot gnu.org
2012-08-12 16:12 ` [Bug fortran/54234] " kargl at gcc dot gnu.org
@ 2012-08-12 16:23 ` tkoenig at gcc dot gnu.org
2012-08-12 19:22 ` burnus at gcc dot gnu.org
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: tkoenig at gcc dot gnu.org @ 2012-08-12 16:23 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54234
Thomas Koenig <tkoenig at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |tkoenig at gcc dot gnu.org
--- Comment #2 from Thomas Koenig <tkoenig at gcc dot gnu.org> 2012-08-12 16:23:19 UTC ---
This is certainly a mistake made by lots of people,
so I think a warning would be appropriate.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug fortran/54234] -Wconversion or -Wconversion-extra should warn for CMPLX(dp,dp)
2012-08-12 14:26 [Bug fortran/54234] New: -Wconversion or -Wconversion-extra should warn for CMPLX(dp,dp) burnus at gcc dot gnu.org
2012-08-12 16:12 ` [Bug fortran/54234] " kargl at gcc dot gnu.org
2012-08-12 16:23 ` tkoenig at gcc dot gnu.org
@ 2012-08-12 19:22 ` burnus at gcc dot gnu.org
2012-08-14 9:35 ` burnus at gcc dot gnu.org
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: burnus at gcc dot gnu.org @ 2012-08-12 19:22 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54234
Tobias Burnus <burnus at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |burnus at gcc dot gnu.org
--- Comment #3 from Tobias Burnus <burnus at gcc dot gnu.org> 2012-08-12 19:21:41 UTC ---
(In reply to comment #1)
> The Fortran standard explicitly states that CMPLX returns
> a complex number with default real kind if the KIND= optional
> argument is not used.
Well, if it weren't valid, gfortran shouldn't warn but print an error. I
recently only found a bug in our program because of a warning about assigning
an REAL to an INTEGER, which should have been a REAL – thus, such warnings can
be helpful.
(In reply to comment #2)
> This is certainly a mistake made by lots of people,
> so I think a warning would be appropriate.
That's also the reason for suggesting this. The question is whether
-Wconversion (which is enabled by -Wall) or -Wconversion-extra (which is hidden
in the manual) is the better choice. It seems to be a somewhat common problem.
The case that one wants to have the default kind but uses a higher-precision
argument, seems to be rather rare; hence, I am inclined to warn already with
-Wconversion/-Wall.
(Side note: REAL always confuses me – for a complex number it returns the kind
of the argument - but for integer/real the default-kind.)
Untested patch – for -Wconversion-extra
--- a/gcc/fortran/check.c
+++ b/gcc/fortran/check.c
@@ -1278,6 +1278,17 @@ gfc_check_cmplx (gfc_expr *x, gfc_expr *y, gfc_expr
*kind)
if (kind_check (kind, 2, BT_COMPLEX) == FAILURE)
return FAILURE;
+ if (y && !kind && gfc_option.warn_conversion_extra
+ && x->ts.type == BT_REAL && x->ts.kind > gfc_default_real_kind)
+ gfc_warning_now ("Conversion from %s to default-kind COMPLEX(%d) at %L "
+ "might loose precision, consider using the KIND argument",
+ gfc_typename (&x->ts), gfc_default_real_kind, &x->where);
+ else if (y && !kind && gfc_option.warn_conversion_extra
+ && y->ts.type == BT_REAL && y->ts.kind > gfc_default_real_kind)
+ gfc_warning_now ("Conversion from %s to default-kind COMPLEX(%d) at %L "
+ "might loose precision, consider using the KIND argument",
+ gfc_typename (&y->ts), gfc_default_real_kind, &y->where);
+
return SUCCESS;
}
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug fortran/54234] -Wconversion or -Wconversion-extra should warn for CMPLX(dp,dp)
2012-08-12 14:26 [Bug fortran/54234] New: -Wconversion or -Wconversion-extra should warn for CMPLX(dp,dp) burnus at gcc dot gnu.org
` (2 preceding siblings ...)
2012-08-12 19:22 ` burnus at gcc dot gnu.org
@ 2012-08-14 9:35 ` burnus at gcc dot gnu.org
2012-08-14 10:22 ` burnus at gcc dot gnu.org
2012-08-14 10:30 ` burnus at gcc dot gnu.org
5 siblings, 0 replies; 7+ messages in thread
From: burnus at gcc dot gnu.org @ 2012-08-14 9:35 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54234
--- Comment #4 from Tobias Burnus <burnus at gcc dot gnu.org> 2012-08-14 09:35:02 UTC ---
Forgot to mention in the initial report that this issue came up at c.l.f, cf.
http://www.rhinocerus.net/forum/lang-fortran/711699-quality-fortran-code-posted-rosettacode.html
But the issue has been risen before.
Submitted patch http://gcc.gnu.org/ml/fortran/2012-08/msg00064.html
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug fortran/54234] -Wconversion or -Wconversion-extra should warn for CMPLX(dp,dp)
2012-08-12 14:26 [Bug fortran/54234] New: -Wconversion or -Wconversion-extra should warn for CMPLX(dp,dp) burnus at gcc dot gnu.org
` (3 preceding siblings ...)
2012-08-14 9:35 ` burnus at gcc dot gnu.org
@ 2012-08-14 10:22 ` burnus at gcc dot gnu.org
2012-08-14 10:30 ` burnus at gcc dot gnu.org
5 siblings, 0 replies; 7+ messages in thread
From: burnus at gcc dot gnu.org @ 2012-08-14 10:22 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54234
--- Comment #5 from Tobias Burnus <burnus at gcc dot gnu.org> 2012-08-14 10:22:11 UTC ---
Author: burnus
Date: Tue Aug 14 10:22:06 2012
New Revision: 190378
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=190378
Log:
2012-08-14 Tobias Burnus <burnus@net-b.de>
PR fortran/54234
* check.c (gfc_check_cmplx): Add -Wconversion warning
when converting higher-precision REAL to default-precision
CMPLX without kind= parameter.
2012-08-14 Tobias Burnus <burnus@net-b.de>
PR fortran/54234
* gfortran.dg/warn_conversion_4.f90: New.
Added:
trunk/gcc/testsuite/gfortran.dg/warn_conversion_4.f90
Modified:
trunk/gcc/fortran/ChangeLog
trunk/gcc/fortran/check.c
trunk/gcc/testsuite/ChangeLog
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug fortran/54234] -Wconversion or -Wconversion-extra should warn for CMPLX(dp,dp)
2012-08-12 14:26 [Bug fortran/54234] New: -Wconversion or -Wconversion-extra should warn for CMPLX(dp,dp) burnus at gcc dot gnu.org
` (4 preceding siblings ...)
2012-08-14 10:22 ` burnus at gcc dot gnu.org
@ 2012-08-14 10:30 ` burnus at gcc dot gnu.org
5 siblings, 0 replies; 7+ messages in thread
From: burnus at gcc dot gnu.org @ 2012-08-14 10:30 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54234
Tobias Burnus <burnus at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |FIXED
--- Comment #6 from Tobias Burnus <burnus at gcc dot gnu.org> 2012-08-14 10:30:42 UTC ---
FIXED on the 4.8 trunk.
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2012-08-14 10:30 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-08-12 14:26 [Bug fortran/54234] New: -Wconversion or -Wconversion-extra should warn for CMPLX(dp,dp) burnus at gcc dot gnu.org
2012-08-12 16:12 ` [Bug fortran/54234] " kargl at gcc dot gnu.org
2012-08-12 16:23 ` tkoenig at gcc dot gnu.org
2012-08-12 19:22 ` burnus at gcc dot gnu.org
2012-08-14 9:35 ` burnus at gcc dot gnu.org
2012-08-14 10:22 ` burnus at gcc dot gnu.org
2012-08-14 10:30 ` burnus at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).