[Bug c++/89550] New: Spurious array-bounds warning when using __PRETTY_FUNCTION__ as a string_view.

2019-03-01 Thread aaron at bestateless dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89550

Bug ID: 89550
   Summary: Spurious array-bounds warning when using
__PRETTY_FUNCTION__ as a string_view.
   Product: gcc
   Version: 8.2.1
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: aaron at bestateless dot com
  Target Milestone: ---

Created attachment 45870
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=45870&action=edit
Preprocessed source.

Compiler Information:
  $ g++ -v
  Using built-in specs.
  COLLECT_GCC=g++
  COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-linux-gnu/8.2.1/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
--enable-cet=auto
  Thread model: posix
  gcc version 8.2.1 20181127 (GCC)

Example:
  #include 

  void foo() {
  std::string_view s(__PRETTY_FUNCTION__);
  s.remove_prefix(s.find_last_of(' '));
  std::string().find(s.data());
  }

Command Line:
  g++ -std=c++17 -Warray-bounds -Werror -O2 -c test.cpp -o test.o

  Does not fail for optimization levels -O0, -O1, or -O3. Only fails for -O2.

Expected:
  Compiles successfully.

  From experiments on https://godbolt.org/ this code compiles on 7.1, 7.2, 7.3,
  7.4, 8.1, 8.2, and trunk. It fails to compile on 8.2.1 and 8.3.0.

Actual:
  test.cpp: In function ‘void foo()’:
  test.cpp:3:6: warning: offset ‘-1’ outside bounds of constant string
[-Warray-bounds]
   void foo() {
^~~

Details:
  This does not fail if the line with "remove_prefix" is commented out. In this
  case __PRETTY_FUNCTION__ does contain a space, so it should not get npos from
  the "find_last_of" call. Also does not fail if the call to "find" is
commented
  out. It is the combination of both lines that causes the warning.

  I can get this to fail in the same way on -O3 if I wrap the function in a
  namespace name that is six characters in length or more. If it is five
  characters or less then it does compile on -O3.

  This example succeeds with "g++ -std=c++17 -Warray-bounds -Werror -O3":

#include 

namespace n
{

void foo() {
std::string_view s(__PRETTY_FUNCTION__);
s.remove_prefix(s.find_last_of(' '));
std::string().find(s.data());
}

}

  This example fails with "g++ -std=c++17 -Warray-bounds -Werror -O3" (note the
  namespace name is longer by one character):

#include 

namespace nn
{

void foo() {
std::string_view s(__PRETTY_FUNCTION__);
s.remove_prefix(s.find_last_of(' '));
std::string().find(s.data());
}

}

[Bug libstdc++/86874] New: std::swap on std::variant fails to compile

2018-08-06 Thread aaron at bestateless dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86874

Bug ID: 86874
   Summary: std::swap on std::variant fails to compile
   Product: gcc
   Version: 8.2.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: libstdc++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: aaron at bestateless dot com
  Target Milestone: ---

Created attachment 44514
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=44514&action=edit
Preprocessed source.

Example:

#include 

int main(int, char**) {
std::variant v1, v2;
std::swap(v1, v2);
}

Expected: Compiles successfully. (Worked for me on g++ 7.3).

Actual:

```
$ g++-8 -v
Using built-in specs.
COLLECT_GCC=g++-8
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/8/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 8.2.0-1'
--with-bugurl=file:///usr/share/doc/gcc-8/README.Bugs
--enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++ --prefix=/usr
--with-gcc-major-version-only --program-suffix=-8
--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 --with-sysroot=/ --enable-clocale=gnu
--enable-libstdcxx-debug --enable-libstdcxx-time=yes
--with-default-libstdcxx-abi=new --enable-gnu-unique-object
--disable-vtable-verify --enable-libmpx --enable-plugin --enable-default-pie
--with-system-zlib --with-target-system-zlib --enable-objc-gc=auto
--enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64
--with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic
--enable-offload-targets=nvptx-none --without-cuda-driver
--enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu
--target=x86_64-linux-gnu
Thread model: posix
gcc version 8.2.0 (Debian 8.2.0-1)

$ g++-8 -std=c++17 test.cpp -save-temps
In file included from test.cpp:1:
/usr/include/c++/8/variant: In instantiation of 'void
std::variant<_Types>::swap(std::variant<_Types>&) [with _Types =
{std::monostate}]':
/usr/include/c++/8/variant:1010:7:   required from
'std::enable_if_t<((is_move_constructible_v<_Types> && ...) &&
(is_swappable_v<_Types> && ...))> std::swap(std::variant<_Types ...>&,
std::variant<_Types ...>&) [with _Types = {std::monostate};
std::enable_if_t<((is_move_constructible_v<_Types> && ...) &&
(is_swappable_v<_Types> && ...))> = void]'
test.cpp:5:21:   required from here
/usr/include/c++/8/variant:1265:12: error: 'class std::variant'
has no member named '_M_destructive_move'
  this->_M_destructive_move(std::move(__rhs));
  ~~^~~
/usr/include/c++/8/variant:1270:12: error: 'class std::variant'
has no member named '_M_destructive_move'
  __rhs._M_destructive_move(std::move(*this));
  ~~^~~
/usr/include/c++/8/variant:1276:12: error: 'class std::variant'
has no member named '_M_destructive_move'
  __rhs._M_destructive_move(std::move(*this));
  ~~^~~
/usr/include/c++/8/variant:1277:12: error: 'class std::variant'
has no member named '_M_destructive_move'
  this->_M_destructive_move(std::move(__tmp));
  ~~^~~
```