Warnings About Symbol Names Beginning with 'TO'
jcburley opened this issue · 4 comments
"Symbol name begins with langauge keyword" (please fix the typo in the penultimate word!) warnings are occurring for names beginning with "TO".
I'm unaware of "TO" being a Fortran language keyword, except possibly in "GOTO" when spelled out as "GO TO", though I can't recall whether free-form source allows that form.
Regardless, in this case it is hardly a problem that the name begins with "TO", assuming there's no statement that begins with "TO".
Generally, I'm not sure what the goal is with this sort of warning. It makes some sense to warn about names like "REALPERSON", since that could be mistaken for "REAL PERSON" in FORTRAN 77 (fixed form).
But to warn about "EXIT" in e.g. "CALL EXIT(0)", when the name refers to a subroutine and so cannot start a statement (nor be assigned to within the subroutine itself, unlike function program units), seems excessively noisy.
In that case, however, I don't know whether the semantic information (as to whether the name refers to a subroutine or some other "innocuous" thing like, say, a common block) is available at the time the diagnostic is generated.
TO is a keyword from the "ASSIGN x TO y" statement, so it's rare that it'd cause an issue but not impossible.
We currently have a "--no-warn-pedantic" which turns off a lot of the annoying verbose warnings.
Also "--no-warn-name-keyword" specifically turns off the keyword in names warning.
I've fixed the typo :)
If the current warnings selection isn't sufficient at the moment then we can certainly add further flags. We're aiming to at some point move towards gcc style invocation.
Could you clarify what sorts of issues might be caused by TO
beginning (or even comprising the entirety of) a name? I'm pretty sure Fortran through 95 didn't actually have any reserved keywords, but haven't kept track of developments since.
Certainly I think we should keep the ability to complain about silly code that uses names like DO
, CALL
, possibly even EXIT
(though that should probably be exempted on the grounds that all Unix-compatible Fortran runtimes offer that as subroutine).
But I'm unclear as to how names like TOTAL
and TODAY
could ever cause a problem.
In between these extremes would be names like FORMATTING
, which begin with a substring that, on its own, could legitimately begin a statement having that substring as its name.
I'm still not sure we want warnings about that middle case (FORMATTING
, FUNCTIONAL
, REALVALUE
, etc.), but I do think we want warnings about REAL
, DO
, END, and no warnings about
TODAY,
TOTAL,
ERROR(if reserved due to e.g.
WRITE(...,ERR=...)`).
I agree mainly. These errors really go back to when we were first working on the compiler and they really helped to understand errors in some of the quirky test programs we did.
I think what really needs to happen is that we differentiate between 3 cases:
"TODAY"
Technically starts with keyword, have opt-in error, not useful generally
"REAL VALUE"
This starts with a keyword and is space separated so it's likely an error, we should warn about this)
"REAL"
This just is a keyword, we should definitely warn about this too.
I've implemented the above now. By default we warn if a variable name IS a keyword, or if it begins with a keyword followed by a space. For the previous behavior there's a flag "--warn-name-keyword-all".
Fixed in commit: 3f6a56d