flang accepts an automatically assigned enum enumerator that is > the max value of the enumerator type
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
Relates to #224030.
The following is accepted by flang but not gfortran:
```fortran
program repro
enum, bind(c)
enumerator :: x = huge(1_4)
enumerator :: y
end enum
end program
```
https://godbolt.org/z/667PMEvhh
gfortran error:
```
4 | enumerator :: y
| 1
Error: ENUMERATOR (1) not initialized with integer expression
Compiler returned: 1
```
It seems correct to error here, but I think the message is misleading because if I adjust the first enumerator then it compiles:
```fortran
program repro
enum, bind(c)
enumerator :: x = huge(1_4) -1
enumerator :: y
end enum
end program
```
So I suspect gfortran is saying that the only valid thing I could do here is give `y` some value that is in the range of kind 4. For instance `= 10` works. The automatic value would be 1 beyond that range.
Note that this was found via. the gfortran test suite so it is a deliberately crafted input. Doesn't seem like a thing most software would try.
Contributor guide
Research direction
Start with the Fortran reproducer in the issue and compare flang's behavior with the linked Godbolt result and gfortran's diagnostic. Confirm the expected handling of an automatically assigned enumerator beyond the kind-4 range, including the adjusted first-enumerator case; done means flang rejects the invalid program consistently.
Written by the indexing model from the issue text.
Assessment
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 65/100