https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93233
Bug ID: 93233 Summary: No warning for possibly uninitialised return Product: gcc Version: 9.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: ada Assignee: unassigned at gcc dot gnu.org Reporter: chris at amtiskaw dot net Target Milestone: --- Created attachment 47637 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=47637&action=edit Test case using normal and extended return syntax. Hi, I'm learning Ada and was surprised to find that the compiler failed to issue a warning when a variable used as the return value of a (simple) function was only conditionally initialised. I discovered this while investigating a bug in a function that used the extended return syntax, so I constructed the following test case which tries both normal and extended returns: with Ada.Text_IO; use Ada.Text_IO; procedure Returns is function Normal(X: in Integer) return Boolean is Result: Boolean; begin if X < 0 then Result := true; end if; return Result; end Normal; function Extended(X: in Integer) return Boolean is begin return Result : Boolean do if X < 0 then Result := true; end if; end return; end Extended; begin Put_Line("Normal(0): " & Normal(0)'Image); Put_Line("Normal(-1): " & Normal(-1)'Image); Put_Line("Extended(0): " & Extended(0)'Image); Put_Line("Extended(-1): " & Extended(-1)'Image); end Returns; Compiling using gnatmake succeeds with no warnings about the potentially uninitialised `Result` from the compiler: $ gnatmake -v -Wall -gnatwa returns.adb GNATMAKE 9.2.1 20190827 (Red Hat 9.2.1-1) Copyright (C) 1992-2019, Free Software Foundation, Inc. "returns.ali" being checked ... -> "returns.ali" missing. gcc -c -Wall -gnatwa returns.adb End of compilation gnatbind -x returns.ali gnatlink returns.ali Running the generated executable gives unpredictable results: $ ./returns Normal(0): TRUE Normal(-1): TRUE Extended(0): FALSE Extended(-1): TRUE $ ./returns Normal(0): FALSE Normal(-1): TRUE Extended(0): FALSE Extended(-1): TRUE I've tried both gcc-gnat 9.2.1 from Fedora 31, and the latest GNAT CE from Adacore with the same results (no warnings). ------------------------------------------------ Platform details - up-to-date Fedora 31, x86_64: GNAT 9.2.1 20190827 (Red Hat 9.2.1-1) Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/9/lto-wrapper OFFLOAD_TARGET_NAMES=nvptx-none OFFLOAD_TARGET_DEFAULT=1 Target: x86_64-redhat-linux Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,objc,obj-c++,ada,go,d,lto --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --with-linker-hash-style=gnu --enable-plugin --enable-initfini-array --with-isl --enable-offload-targets=nvptx-none --without-cuda-driver --enable-gnu-indirect-function --enable-cet --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux Thread model: posix gcc version 9.2.1 20190827 (Red Hat 9.2.1-1) (GCC)