https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83696
Bug ID: 83696 Summary: false positive warning when [[fallthrough]] is inside of if statement Product: gcc Version: 7.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: shyou...@ruby-lang.org Target Milestone: --- Created attachment 43038 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=43038&action=edit reproducible code It seems [[fallthrough]] does not take effect when it is inside of an if statement who has || in the expression. % cat tmp.cpp #pragma GCC diagnostic error "-Wimplicit-fallthrough" int func(int i, int j) { switch (i) { case 0: if ( i || j ) return 1; else [[fallthrough]]; default: return 0; } } % gcc-7 -v -std=c++17 tmp.cpp Using built-in specs. COLLECT_GCC=gcc-7 COLLECT_LTO_WRAPPER=/usr/local/Cellar/gcc/7.2.0/libexec/gcc/x86_64-apple-darwin15.6.0/7.2.0/lto-wrapper Target: x86_64-apple-darwin15.6.0 Configured with: ../configure --build=x86_64-apple-darwin15.6.0 --prefix=/usr/local/Cellar/gcc/7.2.0 --libdir=/usr/local/Cellar/gcc/7.2.0/lib/gcc/7 --enable-languages=c,c++,objc,obj-c++,fortran --program-suffix=-7 --with-gmp=/usr/local/opt/gmp --with-mpfr=/usr/local/opt/mpfr --with-mpc=/usr/local/opt/libmpc --with-isl=/usr/local/opt/isl --with-system-zlib --enable-checking=release --with-pkgversion='Homebrew GCC 7.2.0' --with-bugurl=https://github.com/Homebrew/homebrew-core/issues --disable-nls Thread model: posix gcc version 7.2.0 (Homebrew GCC 7.2.0) COLLECT_GCC_OPTIONS='-v' '-std=c++1z' '-mmacosx-version-min=10.11.6' '-asm_macosx_version_min=10.11' '-mtune=core2' /usr/local/Cellar/gcc/7.2.0/libexec/gcc/x86_64-apple-darwin15.6.0/7.2.0/cc1plus -quiet -v -D__DYNAMIC__ tmp.cpp -fPIC -quiet -dumpbase tmp.cpp -mmacosx-version-min=10.11.6 -mtune=core2 -auxbase tmp -std=c++1z -version -o /var/folders/50/9ss08lxs5ml7kvz614tr3_wmm17741/T//cc2RNpgL.s GNU C++14 (Homebrew GCC 7.2.0) version 7.2.0 (x86_64-apple-darwin15.6.0) compiled by GNU C version 7.2.0, GMP version 6.1.2, MPFR version 3.1.5, MPC version 1.0.3, isl version isl-0.18-GMP warning: MPFR header version 3.1.5 differs from library version 3.1.6. GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 ignoring nonexistent directory "/usr/local/Cellar/gcc/7.2.0/lib/gcc/7/gcc/x86_64-apple-darwin15.6.0/7.2.0/../../../../../../x86_64-apple-darwin15.6.0/include" #include "..." search starts here: #include <...> search starts here: /usr/local/Cellar/gcc/7.2.0/lib/gcc/7/gcc/x86_64-apple-darwin15.6.0/7.2.0/../../../../../../include/c++/7.2.0 /usr/local/Cellar/gcc/7.2.0/lib/gcc/7/gcc/x86_64-apple-darwin15.6.0/7.2.0/../../../../../../include/c++/7.2.0/x86_64-apple-darwin15.6.0 /usr/local/Cellar/gcc/7.2.0/lib/gcc/7/gcc/x86_64-apple-darwin15.6.0/7.2.0/../../../../../../include/c++/7.2.0/backward /usr/local/Cellar/gcc/7.2.0/lib/gcc/7/gcc/x86_64-apple-darwin15.6.0/7.2.0/include /usr/local/include /usr/local/Cellar/gcc/7.2.0/include /usr/local/Cellar/gcc/7.2.0/lib/gcc/7/gcc/x86_64-apple-darwin15.6.0/7.2.0/include-fixed /usr/include /System/Library/Frameworks /Library/Frameworks End of search list. GNU C++14 (Homebrew GCC 7.2.0) version 7.2.0 (x86_64-apple-darwin15.6.0) compiled by GNU C version 7.2.0, GMP version 6.1.2, MPFR version 3.1.5, MPC version 1.0.3, isl version isl-0.18-GMP warning: MPFR header version 3.1.5 differs from library version 3.1.6. GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 Compiler executable checksum: 91ccd58de1ec407f356a7036de6130ed tmp.cpp: In function 'int func(int, int)': tmp.cpp:8:16: error: this statement may fall through [-Werror=implicit-fallthrough=] if ( i || j ) ~~^~~~ tmp.cpp:12:5: note: here default: ^~~~~~~ cc1plus: some warnings being treated as errors [1] 78552 exit 1 gcc-7 -v -std=c++17 tmp.cpp zsh %