https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121221
Bug ID: 121221 Summary: array subscript 'int (**)(...)[0]' is partly outside array bounds of 'f(bool)::A [1]' [-Werror=array-bounds=] Product: gcc Version: 15.1.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: michaelkinrosslim at gmail dot com Target Milestone: --- Created attachment 61943 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=61943&action=edit The preprocessed file gcc -v: Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-linux-gnu/15.1.1/lto-wrapper Target: x86_64-pc-linux-gnu Configured with: /build/gcc/src/gcc/configure --enable-languages=ada,c,c++,d,fortran,go,lto,m2,objc,obj-c++,rust,cobol --enable-bootstrap --prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=https://gitlab.archlinux.org/archlinux/packaging/packages/gcc/-/issues --with-build-config=bootstrap-lto --with-linker-hash-style=gnu --with-system-zlib --enable-__cxa_atexit --enable-cet=auto --enable-checking=release --enable-clocale=gnu --enable-default-pie --enable-default-ssp --enable-gnu-indirect-function --enable-gnu-unique-object --enable-libstdcxx-backtrace --enable-link-serialization=1 --enable-linker-build-id --enable-lto --enable-multilib --enable-plugin --enable-shared --enable-threads=posix --disable-libssp --disable-libstdcxx-pch --disable-werror Thread model: posix Supported LTO compression algorithms: zlib zstd gcc version 15.1.1 20250425 (GCC) Command used: g++ main.cpp -o bin.out -D_GLIBCXX_ASSERTIONS --std=c++23 -O3 -pedantic -Wall -Werror -Wextra -fno-strict-aliasing -fwrapv -fno-aggressive-loop-optimizations This yields: In lambda function, inlined from ‘int f(bool)’ at main.cpp:17:13: main.cpp:14:36: error: array subscript ‘int (**)(...)[0]’ is partly outside array bounds of ‘f(bool)::A [1]’ [-Werror=array-bounds=] 14 | return (a.*member_function)(); | ~~~~~~~~~~~~~~~~~~~~^~ main.cpp: In function ‘int f(bool)’: main.cpp:9:7: note: object ‘a’ of size 1 9 | } a; | ^ cc1plus: all warnings being treated as errors The code to reproduce this can be found here https://godbolt.org/z/h9h8qG9d8. Observations: Changing to value capture stops the warning. Moving the variable 'a' into the lambda stops the warning, however also using std::invoke instead of (a.*member_function)() triggers the warning again. Passing relative_diagonal as a parameter instead of a capture also stops the error. Changing optimization level to O1 stops the warning. Replacing the ternary with &A::fun stops the warning.