https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91873

            Bug ID: 91873
           Summary: -Wreturn-type diagnostic location changes depending on
                    optimization level and destructor declaration
           Product: gcc
           Version: 9.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: m101010a at gmail dot com
  Target Milestone: ---

$ cat x.cpp
struct s {
#ifdef HAS_DESTRUCTOR
    ~s();
#endif
};
bool f();
int g()
{
    s buf;
    if (f())
        return 0;
}
$ g++ -Werror=return-type -O0 x.cpp
x.cpp: In function ‘int g()’:
x.cpp:12:1: error: control reaches end of non-void function
[-Werror=return-type]
   12 | }
      | ^
cc1plus: some warnings being treated as errors
$ g++ -Werror=return-type -O1 x.cpp
x.cpp: In function ‘int g()’:
x.cpp:12:1: error: control reaches end of non-void function
[-Werror=return-type]
   12 | }
      | ^
cc1plus: some warnings being treated as errors
$ g++ -Werror=return-type -DHAS_DESTRUCTOR -O0 x.cpp
x.cpp: In function ‘int g()’:
x.cpp:12:1: error: control reaches end of non-void function
[-Werror=return-type]
   12 | }
      | ^
cc1plus: some warnings being treated as errors
$ g++ -Werror=return-type -DHAS_DESTRUCTOR -O1 x.cpp
x.cpp: In function ‘int g()’:
x.cpp:9:7: error: control reaches end of non-void function
[-Werror=return-type]
    9 |     s buf;
      |       ^~~
cc1plus: some warnings being treated as errors
$ g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-linux-gnu/9.1.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /build/gcc/src/gcc/configure --prefix=/usr --libdir=/usr/lib
--libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info
--with-bugurl=https://bugs.archlinux.org/
--enable-languages=c,c++,ada,fortran,go,lto,objc,obj-c++ --enable-shared
--enable-threads=posix --with-system-zlib --with-isl --enable-__cxa_atexit
--disable-libunwind-exceptions --enable-clocale=gnu --disable-libstdcxx-pch
--disable-libssp --enable-gnu-unique-object --enable-linker-build-id
--enable-lto --enable-plugin --enable-install-libiberty
--with-linker-hash-style=gnu --enable-gnu-indirect-function --enable-multilib
--disable-werror --enable-checking=release --enable-default-pie
--enable-default-ssp --enable-cet=auto
Thread model: posix
gcc version 9.1.0 (GCC) 

When -Wreturn-type locates the end of a function that has a variable with a
non-trivial destructor, it will point at the closing brace when compiling with
-O0, but points at the variable at -O1 and higher.  This behavior was
introduced in GCC 8; GCC 7 always pointed at the closing brace.

Reply via email to