public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/94655] New: Implicit assignment operator triggers stringop-overflow warning
@ 2020-04-18 23:35 drahflow at gmx dot de
  2020-04-20  7:10 ` [Bug tree-optimization/94655] [10 Regression] " rguenth at gcc dot gnu.org
                   ` (22 more replies)
  0 siblings, 23 replies; 24+ messages in thread
From: drahflow at gmx dot de @ 2020-04-18 23:35 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94655

            Bug ID: 94655
           Summary: Implicit assignment operator triggers
                    stringop-overflow warning
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: drahflow at gmx dot de
  Target Milestone: ---

Running:

g++-10 -O3 -W -Wall -Wextra -Werror --std=c++2a -c problem.c++

on this code:

#include <functional>
#include <memory>
#include <string>

struct A {
  std::string strA; // remove this line and it works
  char arr[16]; // remove this line and it works
  std::string strB; // remove this line and it works
};

const A getA(); // remove "const" and it works

void frob(const std::function<void()> &);

struct B {
  int i; // remove this line and it works
  A data;

  B() { }

  void f();
};

void B::f() {
  frob([this]() {
    data = getA();
  });

  // data = getA(); // comment out the frob(...) and use this line, it works
}

results in:

In member function ‘A& A::operator=(const A&)’,
    inlined from ‘B::f()::<lambda()>’ at problem.c++:26:17,
    inlined from ‘constexpr _Res std::__invoke_impl(std::__invoke_other, _Fn&&,
_Args&& ...) [with _Res = void; _Fn = B::f()::<lambda()>&; _Args = {}]’ at
/usr/include/c++/10/bits/invoke.h:60:36,
    inlined from ‘constexpr std::enable_if_t<is_invocable_r_v<_Res, _Callable,
_Args ...>, _Res> std::__invoke_r(_Callable&&, _Args&& ...) [with _Res = void;
_Callable = B::f()::<lambda()>&; _Args = {}]’ at
/usr/include/c++/10/bits/invoke.h:110:28,
    inlined from ‘static _Res std::_Function_handler<_Res(_ArgTypes ...),
_Functor>::_M_invoke(const std::_Any_data&, _ArgTypes&& ...) [with _Res = void;
_Functor = B::f()::<lambda()>; _ArgTypes = {}]’ at
/usr/include/c++/10/bits/std_function.h:291:30:
problem.c++:5:8: error: writing 16 bytes into a region of size 0
[-Werror=stringop-overflow=]
    5 | struct A {
      |        ^
problem.c++: In static member function ‘static _Res
std::_Function_handler<_Res(_ArgTypes ...), _Functor>::_M_invoke(const
std::_Any_data&, _ArgTypes&& ...) [with _Res = void; _Functor =
B::f()::<lambda()>; _ArgTypes = {}]’:
problem.c++:6:15: note: at offset 0 to object ‘A::strA’ with size 32 declared
here
    6 |   std::string strA; // remove this line and it works
      |               ^~~~


Using instead -O2, it works.
Using instead g++9, it works.

% g++-10 --version
g++-10 (Debian 10-20200222-1) 10.0.1 20200222 (experimental) [master revision
01af7e0a0c2:487fe13f218:e99b18cf7101f205bfdd9f0f29ed51caaec52779]

^ permalink raw reply	[flat|nested] 24+ messages in thread

end of thread, other threads:[~2023-07-07  8:49 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-18 23:35 [Bug c++/94655] New: Implicit assignment operator triggers stringop-overflow warning drahflow at gmx dot de
2020-04-20  7:10 ` [Bug tree-optimization/94655] [10 Regression] " rguenth at gcc dot gnu.org
2020-04-20  7:24 ` [Bug tree-optimization/94655] [10 Regression] Implicit assignment operator triggers stringop-overflow warning since r10-5451-gef29b12cfbb4979a marxin at gcc dot gnu.org
2020-04-20  8:52 ` jakub at gcc dot gnu.org
2020-04-20 15:35 ` msebor at gcc dot gnu.org
2020-04-20 15:42 ` jakub at gcc dot gnu.org
2020-04-20 16:57 ` msebor at gcc dot gnu.org
2020-04-21 20:10 ` law at redhat dot com
2020-04-21 21:27 ` msebor at gcc dot gnu.org
2020-04-30 16:14 ` [Bug tree-optimization/94655] [10/11 " msebor at gcc dot gnu.org
2020-05-07 11:56 ` jakub at gcc dot gnu.org
2020-07-21 14:55 ` msebor at gcc dot gnu.org
2020-07-21 20:08 ` msebor at gcc dot gnu.org
2020-07-21 20:46 ` pinskia at gcc dot gnu.org
2020-07-23  6:51 ` rguenth at gcc dot gnu.org
2021-01-14  8:38 ` rguenth at gcc dot gnu.org
2021-01-14 20:11 ` msebor at gcc dot gnu.org
2021-01-21 22:34 ` [Bug tree-optimization/94655] [10/11 Regression] -Wstringop-overflow on implicit string assignment with vectorized char store msebor at gcc dot gnu.org
2021-01-21 23:48 ` msebor at gcc dot gnu.org
2021-03-04  0:05 ` cvs-commit at gcc dot gnu.org
2021-04-08 12:02 ` [Bug tree-optimization/94655] [10 " rguenth at gcc dot gnu.org
2022-03-17 19:54 ` msebor at gcc dot gnu.org
2022-06-28 10:40 ` jakub at gcc dot gnu.org
2023-07-07  8:49 ` rguenth at gcc dot gnu.org

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).