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

            Bug ID: 84657
           Summary: Wrong exception type matched in catch clause when
                    compiled with address sanitizer
           Product: gcc
           Version: 7.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: mikezackles at gmail dot com
  Target Milestone: ---

Created attachment 43538
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=43538&action=edit
preprocessed

See below for minimal reproduction. Thanks!

$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-linux-gnu/7.3.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 --enable-libmpx --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
Thread model: posix
gcc version 7.3.0 (GCC)

$ cat main.cpp 
#include <iostream>
#include <stdexcept>

namespace {

int thisThrows() {
  throw std::runtime_error( "This shouldn't be caught" );
  return 1;
}

struct SomeRandomType {};

}

int main() {
  try {
    static_cast<void>(thisThrows());
  }
  catch( SomeRandomType& ) {
    std::cout << "This shouldn't happen!" << std::endl;
  }
}

$ g++ -fsanitize=address -fno-omit-frame-pointer -O0 -g main.cpp && ./a.out
This shouldn't happen!

$ g++ -O0 -g main.cpp && ./a.out
terminate called after throwing an instance of 'std::runtime_error'
  what():  This shouldn't be caught
Aborted (core dumped)

$ clang++ -fsanitize=address -fno-omit-frame-pointer -O0 -g main.cpp && ./a.out
terminate called after throwing an instance of 'std::runtime_error'
  what():  This shouldn't be caught
Aborted (core dumped)

$ clang++ --version
clang version 5.0.1 (tags/RELEASE_501/final)

$ cat /etc/os-release
NAME="Arch Linux"

Note that I have tried this with gcc trunk on my system and the issue does not
occur. This is similar to bug 78651. See also
https://github.com/google/sanitizers/issues/919

Reply via email to