[Bug c++/107138] [12 regression] std::variant triggers false-positive 'may be used uninitialized' warning

2022-10-03 Thread carsten.andrich at gmx dot de via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107138

--- Comment #2 from carsten.andrich at gmx dot de ---
(In reply to Marek Polacek from comment #1)
> I see the warning even without -fsanitize=undefined.

Yes. Just used -fsanitize=undefined as per the bug writing guidelines.

What I forgot to mention though: The issue only occurs with -O2 or higher. -O1
and -Og compile without the warnings.

[Bug c++/107138] New: [12 regression] std::variant triggers false-positive 'may be used uninitialized' warning

2022-10-03 Thread carsten.andrich at gmx dot de via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107138

Bug ID: 107138
   Summary: [12 regression] std::variant
triggers false-positive 'may be used uninitialized'
warning
   Product: gcc
   Version: 12.2.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: carsten.andrich at gmx dot de
  Target Milestone: ---

Created attachment 53660
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=53660=edit
.ii file as per bug writing guidelines

Compiling the following code using an std::string inside an std::variant
compiles without warnings on g++ 10.4.0 and 11.3.0 as well as clang++ 14.0.6
with -std=c++17 -Wall -Wextra -O2 -fsanitize=undefined:

```
#include 
#include 
#include 

class Toml {
public:
class Array;

typedef std::variant value_t;

class Array {
public:
std::vector data;

Array(const std::vector )
{
this->data.reserve(data.size());
for (const double  : data) {
this->data.push_back(elem);
}
}
};
};

int main(int argc, char *argv[])
{
(void) argc;
(void) argv;

std::vector a = { 42., 42. };
auto array = Toml::Array(a);

return 0;
}
```

However on g++ 12.2.0 as well as gcc 13 trunk (https://godbolt.org/z/6MqGWcPhr)
it triggers what I believe are several false positive 'may be used
uninitialized' warnings. Removing the std::string from the std::variant
resolves the issue.

```
Using built-in specs.
COLLECT_GCC=g++-12
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/12/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 12.2.0-4'
--with-bugurl=file:///usr/share/doc/gcc-12/README.Bugs
--enable-languages=c,ada,c++,go,d,fortran,objc,obj-c++,m2 --prefix=/usr
--with-gcc-major-version-only --program-suffix=-12
--program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id
--libexecdir=/usr/lib --without-included-gettext --enable-threads=posix
--libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug
--enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new
--enable-gnu-unique-object --disable-vtable-verify --enable-plugin
--enable-default-pie --with-system-zlib --enable-libphobos-checking=release
--with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch
--disable-werror --enable-cet --with-arch-32=i686 --with-abi=m64
--with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic
--enable-offload-targets=nvptx-none=/build/gcc-12-zSjAmm/gcc-12-12.2.0/debian/tmp-nvptx/usr,amdgcn-amdhsa=/build/gcc-12-zSjAmm/gcc-12-12.2.0/debian/tmp-gcn/usr
--enable-offload-defaulted --without-cuda-driver --enable-checking=release
--build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 12.2.0 (Debian 12.2.0-4) 
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-std=c++17' '-Wall' '-Wextra' '-O2'
'-o' 'gcc_bug' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
 /usr/lib/gcc/x86_64-linux-gnu/12/cc1plus -E -quiet -v -imultiarch
x86_64-linux-gnu -D_GNU_SOURCE gcc_bug.cpp -mtune=generic -march=x86-64
-std=c++17 -Wall -Wextra -O2 -fpch-preprocess -fasynchronous-unwind-tables -o
gcc_bug.ii
ignoring duplicate directory "/usr/include/x86_64-linux-gnu/c++/12"
ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"
ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/12/include-fixed"
ignoring nonexistent directory
"/usr/lib/gcc/x86_64-linux-gnu/12/../../../../x86_64-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/include/c++/12
 /usr/include/x86_64-linux-gnu/c++/12
 /usr/include/c++/12/backward
 /usr/lib/gcc/x86_64-linux-gnu/12/include
 /usr/local/include
 /usr/include/x86_64-linux-gnu
 /usr/include
End of search list.
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-std=c++17' '-Wall' '-Wextra' '-O2'
'-o' 'gcc_bug' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
 /usr/lib/gcc/x86_64-linux-gnu/12/cc1plus -fpreprocessed gcc_bug.ii -quiet
-dumpbase gcc_bug.cpp -dumpbase-ext .cpp -mtune=generic -march=x86-64 -O2 -Wall
-Wextra -std=c++17 -version -fasynchronous-unwind-tables -o gcc_bug.s
GNU C++17 (Debian 12.2.0-4) version 12.2.0 (x86_64-linux-gnu)
compiled by GNU C version 12.2.0, GMP version 6.2.1, MPFR version
4.1.0, MPC version 1.2.1, isl version isl-0.25-GMP

GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
GNU C++17 (Debian 12.2.0-4) version 12.2.0 (x86_64-linux-gnu)
compiled by GNU C version 12.2.0, GMP version 6.2.1, MPFR version
4.1.0, MPC version 1.2.1, isl version isl-0.25-GMP

GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072