public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "m101010a at gmail dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/101831] New: Spurious maybe-uninitialized warning on std::array::size Date: Mon, 09 Aug 2021 16:13:12 +0000 [thread overview] Message-ID: <bug-101831-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101831 Bug ID: 101831 Summary: Spurious maybe-uninitialized warning on std::array::size Product: gcc Version: 11.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: m101010a at gmail dot com Target Milestone: --- When calling std::array::size on an uninitialized array, gcc emits a warning: $ cat x.cpp #include <array> int f() { std::array<char, 1> a; return a.size(); } $ g++ -v -S -o /dev/null -Wmaybe-uninitialized x.cpp Using built-in specs. COLLECT_GCC=g++ 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++,d --with-isl --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-install-libiberty --enable-linker-build-id --enable-lto --enable-multilib --enable-plugin --enable-shared --enable-threads=posix --disable-libssp --disable-libstdcxx-pch --disable-libunwind-exceptions --disable-werror gdc_include_dir=/usr/include/dlang/gdc Thread model: posix Supported LTO compression algorithms: zlib zstd gcc version 11.1.0 (GCC) COLLECT_GCC_OPTIONS='-v' '-S' '-o' '/dev/null' '-Wmaybe-uninitialized' '-shared-libgcc' '-mtune=generic' '-march=x86-64' '-dumpdir' '/dev/' /usr/lib/gcc/x86_64-pc-linux-gnu/11.1.0/cc1plus -quiet -v -D_GNU_SOURCE x.cpp -quiet -dumpdir /dev/ -dumpbase x.cpp -dumpbase-ext .cpp -mtune=generic -march=x86-64 -Wmaybe-uninitialized -version -o /dev/null GNU C++17 (GCC) version 11.1.0 (x86_64-pc-linux-gnu) compiled by GNU C version 11.1.0, GMP version 6.2.1, MPFR version 4.1.0, MPC version 1.2.1, isl version isl-0.24-GMP warning: MPFR header version 4.1.0 differs from library version 4.1.0-p13. GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 ignoring nonexistent directory "/usr/lib/gcc/x86_64-pc-linux-gnu/11.1.0/../../../../x86_64-pc-linux-gnu/include" #include "..." search starts here: #include <...> search starts here: /usr/lib/gcc/x86_64-pc-linux-gnu/11.1.0/../../../../include/c++/11.1.0 /usr/lib/gcc/x86_64-pc-linux-gnu/11.1.0/../../../../include/c++/11.1.0/x86_64-pc-linux-gnu /usr/lib/gcc/x86_64-pc-linux-gnu/11.1.0/../../../../include/c++/11.1.0/backward /usr/lib/gcc/x86_64-pc-linux-gnu/11.1.0/include /usr/local/include /usr/lib/gcc/x86_64-pc-linux-gnu/11.1.0/include-fixed /usr/include End of search list. GNU C++17 (GCC) version 11.1.0 (x86_64-pc-linux-gnu) compiled by GNU C version 11.1.0, GMP version 6.2.1, MPFR version 4.1.0, MPC version 1.2.1, isl version isl-0.24-GMP warning: MPFR header version 4.1.0 differs from library version 4.1.0-p13. GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 Compiler executable checksum: 45eb9a71cc15bfdc579557bea4b77e51 x.cpp: In function ‘int f()’: x.cpp:4:22: warning: ‘a’ may be used uninitialized [-Wmaybe-uninitialized] 4 | return a.size(); | ~~~~~~^~ In file included from x.cpp:1: /usr/include/c++/11.1.0/array:176:7: note: by argument 1 of type ‘const std::array<char, 1>*’ to ‘constexpr std::array<_Tp, _Nm>::size_type std::array<_Tp, _Nm>::size() const [with _Tp = char; long unsigned int _Nm = 1]’ declared here 176 | size() const noexcept { return _Nm; } | ^~~~ x.cpp:3:29: note: ‘a’ declared here 3 | std::array<char, 1> a; | ^ COMPILER_PATH=/usr/lib/gcc/x86_64-pc-linux-gnu/11.1.0/:/usr/lib/gcc/x86_64-pc-linux-gnu/11.1.0/:/usr/lib/gcc/x86_64-pc-linux-gnu/:/usr/lib/gcc/x86_64-pc-linux-gnu/11.1.0/:/usr/lib/gcc/x86_64-pc-linux-gnu/ LIBRARY_PATH=/usr/lib/gcc/x86_64-pc-linux-gnu/11.1.0/:/usr/lib/gcc/x86_64-pc-linux-gnu/11.1.0/../../../../lib/:/lib/../lib/:/usr/lib/../lib/:/usr/lib/gcc/x86_64-pc-linux-gnu/11.1.0/../../../:/lib/:/usr/lib/ COLLECT_GCC_OPTIONS='-v' '-S' '-o' '/dev/null' '-Wmaybe-uninitialized' '-shared-libgcc' '-mtune=generic' '-march=x86-64' '-dumpdir' '/dev/' It also happens on the following reduced test case: struct array { int d; int e() const { return 1; } }; int f() { array a; return a.e(); } This does not happen when optimization is enabled, and does not happen if "-fsyntax-only" is used instead of "-S -o /dev/null". This also happens with GCC 11.2, but does not happen with GCC 10.
next reply other threads:[~2021-08-09 16:13 UTC|newest] Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-08-09 16:13 m101010a at gmail dot com [this message] 2021-08-16 19:18 ` [Bug tree-optimization/101831] " msebor at gcc dot gnu.org 2022-01-21 21:32 ` kim.walisch at gmail dot com 2022-01-24 21:31 ` [Bug tree-optimization/101831] [11/12 Regression] " msebor at gcc dot gnu.org 2022-01-27 21:34 ` msebor at gcc dot gnu.org 2022-01-28 2:03 ` pinskia at gcc dot gnu.org 2022-02-01 18:54 ` msebor at gcc dot gnu.org 2022-02-02 0:22 ` cvs-commit at gcc dot gnu.org 2022-02-02 0:24 ` [Bug tree-optimization/101831] [11 " msebor at gcc dot gnu.org 2022-04-21 7:50 ` rguenth at gcc dot gnu.org 2023-05-29 10:05 ` jakub at gcc dot gnu.org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-101831-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).