From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22146 invoked by alias); 16 Jun 2013 23:28:41 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 22116 invoked by uid 48); 16 Jun 2013 23:28:38 -0000 From: "furue at hawaii dot edu" To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/57628] spurious error: division by zero in if statement Date: Sun, 16 Jun 2013 23:28:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: fortran X-Bugzilla-Version: 4.7.3 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: furue at hawaii dot edu X-Bugzilla-Status: RESOLVED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2013-06/txt/msg00885.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57628 --- Comment #9 from Ryo Furue --- (In reply to Steve Kargl from comment #8) > So, the compiler should just arbitrarily chose to evaluate > some expression and ignore others? No, I don't mean that. I'm not saying which expression the compiler should evaluate. What I'm saying is, what is the best way to deal with the result of the evaluation? The compiler "can" (or "should"?) evaluate 1/a at compile time if a is a parameter. But, it's "useful" to provide an option that allows the compiler to let the code pass even if a == 0 (with a warning message, perhaps). That's what I argue. I don't think the compiler "must" evaluate "1/a" or "a>0" at compile time. It's at the compiler's discretion. But, whatever it does "should" be maximally "useful" (as long as the chosen behavior does not violate the Fortran standard). > Just remove the PARAMETER attribute in your code, it it will > do what you. > > real :: a = 0 > if (a > 0) then > print *, 1/a [. . .] Yes, I was about to come to that! I write my code that way because I plan to provide the value of "a" from an external module in the future. Currently I set the value with PARAMETER just as a convenience during the development of the code. So, you are right, that your solution is one workaround for my situation. But, I feel strongly uneasy looking at the code because "real::a = 0" is a strong indication that the value of "a" will be altered after the definition. The codes we are showing in this message exchange are shortened versions and in my real codes, there are some lines between "real, parameter:: a = 0" and the IF statement. When I see "real:: a = 0.0", I expect the value of "a" will be altered because I don't see PARAMETER. Also, I still don't like this (sort of) "inconsistency". It's more natural to expect the outcome of the code be the same whether it's "real, parameter:: a = 0" or "real:: a = 0". Another example is, real, parameter:: a = -1.0 if (a > 0) write(*,*) sqrt(a) This does not compile. If we replace sqrt with yoursqrt, it compiles. (I know the reason why gfortran does this. That's not my question.) Overall, I think this kind of thing is better be a "warning" and that at least the compiler should allow the user to run such a code as this. The result of the run may be a disaster but it's the user's responsibility. To refuse to compile these codes is too much patronizing on the part of the compiler. Cheers, Ryo P.S. How does this interact with the IEEE support of F2003? I may be wrong, but I thought that replacing 1.0/0.0 with "Inf" at compile time would be a useful extension (without violating the Fortran standard, of course). Again, I'm not saying the compiler must do this. All I'm saying is that it may be useful.