# \`gfortran-14\`: "MEM \<real(kind=4)\[0:\]\> \[(real(kind=4)\[0:\] \*)\_32\]\[0\]’ may be used uninitialized"

**URL:** <https://fortran-lang.discourse.group/t/gfortran-14-mem-real-kind-4-0-real-kind-4-0-32-0-may-be-used-uninitialized/10322>\
**Category:** Uncategorized\
**Created:** [August 11, 2025, 8:23am UTC](https://fortran-lang.discourse.group/t/gfortran-14-mem-real-kind-4-0-real-kind-4-0-32-0-may-be-used-uninitialized/10322 "2025-08-11T08:23:17Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![zaikunzhang](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/zaikunzhang/32/785_2.png) [@zaikunzhang](https://fortran-lang.discourse.group/u/zaikunzhang)\
**Post date:** [August 11, 2025, 8:23am UTC](https://fortran-lang.discourse.group/t/gfortran-14-mem-real-kind-4-0-real-kind-4-0-32-0-may-be-used-uninitialized/10322/1 "2025-08-11T08:23:17Z")

</div>

When playing with `gfortran-14.2.0`, I encountered an issue with `-Wmaybe-uninitialized` as illustrated below.

```plaintext
$ uname -a && gfortran --version && gfortran -Werror -Wuninitialized -fsanitize=undefined -O2 test_uninit.f90 
Linux 6.14.0-27-generic #27~24.04.1-Ubuntu SMP PREEMPT_DYNAMIC Tue Jul 22 17:38:49 UTC 2 x86_64 x86_64 x86_64 GNU/Linux
GNU Fortran (Ubuntu 14.2.0-4ubuntu2~24.04) 14.2.0
Copyright (C) 2024 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

test_uninit.f90:36:19:

   36 | f = [(0.0, i=1, k)]
      | ^
Error: ‘MEM <real(kind=4)[0:]> [(real(kind=4)[0:] *)_32][0]’ may be used uninitialized [-Werror=maybe-uninitialized]
f951: all warnings being treated as errors

```

Here, test\_uninit.f90 is the code below (see also [test\_compiler/test\_uninit.f90 at master · zequipe/test\_compiler · GitHub](https://github.com/zequipe/test_compiler/blob/master/test_uninit.f90)).

````fortran
!--------------------------------------------------------------------------------------------------!
! test_uninit.f90
!
! This test illustrates a bug in gfortran 14. With
! ```
! gfortran -Werror -Wuninitialized -fsanitize=undefined -O2 test_uninit.f90
! ```
! or
! ```
! gfortran -Werror -Wmaybe-uninitialized -fsanitize=undefined -O2 test_uninit.f90
! ```
! it fails with:
! ```
! test_uninit.f90:36:19:
!
! 36 | f = [(0.0, i=1, k)]
! | ^
! Error: ‘MEM <real(kind=4)[0:]> [(real(kind=4)[0:] *)_32][0]’ may be used uninitialized [-Werror=maybe-uninitialized]
! f951: all warnings being treated as errors
! ```
! Even with `Wuninitialized`, the error is still `-Werror=maybe-uninitialized`.
! The same error occurs with `-O3`, `-O4`, and `-Ofast`, but not with `-O` `-O0`, or `-O1`.
!--------------------------------------------------------------------------------------------------!
module test_mod
implicit none
private
public :: test

contains

subroutine test(k)
implicit none
integer(8), intent(in) :: k
integer(8) :: i
real :: f(k)
f = [(0.0, i=1, k)]
f = 0.0
end subroutine test
end module test_mod

program test_program
end program test_program

````

Any idea why this happens? Thanks.

**N.B**

1. This example is **minimal**. Any change to the code or the compiler flags will make the error disappear.
2. Surely, `integer(8)` is not standard-conforming. I wrote it in this way because `gfortran` is the only compiler concerned. I would not write this kind of code in production.
3. Even with `-Wuninitialized`, the error still says “-Werror=maybe-uninitialized”.

---

<div class="post-metadata">

**Author:** ![PierU](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/pieru/32/1848_2.png) [@PierU](https://fortran-lang.discourse.group/u/PierU)\
**Post date:** [August 11, 2025, 10:11am UTC](https://fortran-lang.discourse.group/t/gfortran-14-mem-real-kind-4-0-real-kind-4-0-32-0-may-be-used-uninitialized/10322/2 "2025-08-11T10:11:35Z")

</div>

Looks like a false positive

---

<div class="post-metadata">

**Author:** ![eugene\_epshteyn](https://avatars.discourse-cdn.com/v4/letter/e/8797f3/32.png) [@eugene\_epshteyn](https://fortran-lang.discourse.group/u/eugene_epshteyn)\
**Post date:** [August 11, 2025, 12:40pm UTC](https://fortran-lang.discourse.group/t/gfortran-14-mem-real-kind-4-0-real-kind-4-0-32-0-may-be-used-uninitialized/10322/3 "2025-08-11T12:40:28Z")

</div>

A guess: because of second initialization `f = 0.0`, compiler may be optimizing out the first initialization. Once the first initialization is optimized out, `i` will not be used and will not be initialized.

---

<div class="post-metadata">

**Author:** ![septc](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/septc/32/77_2.png) [@septc](https://fortran-lang.discourse.group/u/septc)\
**Post date:** [August 12, 2025, 3:45am UTC](https://fortran-lang.discourse.group/t/gfortran-14-mem-real-kind-4-0-real-kind-4-0-32-0-may-be-used-uninitialized/10322/4 "2025-08-12T03:45:22Z")

</div>

> **[Instrumentation Options (Using the GNU Compiler Collection (GCC))](https://gcc.gnu.org/onlinedocs/gcc/Instrumentation-Options.html#index-fsanitize_003dundefined)**
>
> Instrumentation Options (Using the GNU Compiler Collection (GCC))

FWIW, the above page has a comment like this (at the end of the `-fsanitize=undefined` section):

> Note that sanitizers tend to increase the rate of false positive warnings, most notably those around -Wmaybe-uninitialized. We recommend against combining -Werror and [the use of] sanitizers.

I’ve also experienced similar warnings several times, but in my cases they had no actual problems in the computed results (but of course, YMMV). So I often attached `-Wno-maybe-uninitialized` to suppress those warnings. It may be useful to compare outputs with other versions (including newer ones) if possible.

---

<div class="post-metadata">

**Author:** ![zaikunzhang](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/zaikunzhang/32/785_2.png) [@zaikunzhang](https://fortran-lang.discourse.group/u/zaikunzhang)\
**Post date:** [August 12, 2025, 7:41am UTC](https://fortran-lang.discourse.group/t/gfortran-14-mem-real-kind-4-0-real-kind-4-0-32-0-may-be-used-uninitialized/10322/5 "2025-08-12T07:41:48Z")

</div>

> [@septc](#):
>
> It may be useful to compare outputs with other versions (including newer ones) if possible.

The same error occurs with gfortran 14.1.0, 14.2.0, 14.3.0, 15.1.0, and 15.2.0, but not with 13.4.0 or lower.

---

<div class="post-metadata">

**Author:** ![zaikunzhang](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/zaikunzhang/32/785_2.png) [@zaikunzhang](https://fortran-lang.discourse.group/u/zaikunzhang)\
**Post date:** [August 12, 2025, 7:44am UTC](https://fortran-lang.discourse.group/t/gfortran-14-mem-real-kind-4-0-real-kind-4-0-32-0-may-be-used-uninitialized/10322/6 "2025-08-12T07:44:58Z")

</div>

> [@eugene\_epshteyn](#):
>
> A guess: because of second initialization `f = 0.0`, compiler may be optimizing out the first initialization. Once the first initialization is optimized out, `i` will not be used and will not be initialized.

This is a reasonable guess. However, the real reason seems more unreasonable, because the following code encounters the same error.

````fortran
!--------------------------------------------------------------------------------------------------!
! test_uninit.f90
!
! This test illustrates a bug in gfortran 14. With
! ```
! gfortran -Werror -Wuninitialized -fsanitize=undefined -O2 test_uninit.f90
! ```
! or
! ```
! gfortran -Werror -Wmaybe-uninitialized -fsanitize=undefined -O2 test_uninit.f90
! ```
! it fails with:
! ```
! test_uninit.f90:36:19:
!
! 36 | f = [(0.0, i=1, k)]
! | ^
! Error: ‘MEM <real(kind=4)[0:]> [(real(kind=4)[0:] *)_32][0]’ may be used uninitialized [-Werror=maybe-uninitialized]
! f951: all warnings being treated as errors
! ```
! Even with `Wuninitialized`, the error is still `-Werror=maybe-uninitialized`.
! The same error occurs with `-O3`, `-O4`, and `-Ofast`, but not with `-O` `-O0`, or `-O1`.
!--------------------------------------------------------------------------------------------------!
module test_mod
implicit none
private
public :: test

contains

subroutine test(k)
implicit none
integer(8), intent(in) :: k
integer(8) :: i
real :: f(k), x(k)
f = [(0.0, i=1, k)]
x = 0.0
end subroutine test
end module test_mod

program test_program
end program test_program

````
