diff options
author | Martin Sebor <msebor@redhat.com> | 2018-01-14 21:54:25 +0000 |
---|---|---|
committer | Martin Sebor <msebor@gcc.gnu.org> | 2018-01-14 14:54:25 -0700 |
commit | 656280b0b4d9ecd546e93ab9061aa76513b40b5b (patch) | |
tree | 543386027ab500aa0d494cb5dade74467da5b15f | |
parent | ba791a6c72d06778670686afba661ecba43fd77b (diff) | |
download | gcc-656280b0b4d9ecd546e93ab9061aa76513b40b5b.zip gcc-656280b0b4d9ecd546e93ab9061aa76513b40b5b.tar.gz gcc-656280b0b4d9ecd546e93ab9061aa76513b40b5b.tar.bz2 |
PR c++/81327 - cast to void* does not suppress -Wclass-memaccess
gcc/ChangeLog:
PR c++/81327
* doc/invoke.texi (-Wlass-memaccess): Document suppression by casting.
From-SVN: r256677
-rw-r--r-- | gcc/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/doc/invoke.texi | 23 |
2 files changed, 18 insertions, 10 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 61a13aa..5934cc0 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2018-01-14 Martin Sebor <msebor@redhat.com> + + PR c++/81327 + * doc/invoke.texi (-Wlass-memaccess): Document suppression by casting. + 2018-01-14 Jakub Jelinek <jakub@redhat.com> * config.gcc (i[34567]86-*-*): Remove one duplicate gfniintrin.h diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 9ea765e..f57c058 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -2956,20 +2956,23 @@ C++17 it calls @code{f<void(*)()noexcept>}. @item -Wclass-memaccess @r{(C++ and Objective-C++ only)} @opindex Wclass-memaccess Warn when the destination of a call to a raw memory function such as -@code{memset} or @code{memcpy} is an object of class type writing into which -might bypass the class non-trivial or deleted constructor or copy assignment, -violate const-correctness or encapsulation, or corrupt the virtual table. -Modifying the representation of such objects may violate invariants maintained -by member functions of the class. For example, the call to @code{memset} -below is undefined because it modifies a non-trivial class object and is, -therefore, diagnosed. The safe way to either initialize or clear the storage -of objects of such types is by using the appropriate constructor or assignment -operator, if one is available. +@code{memset} or @code{memcpy} is an object of class type, and when writing +into such an object might bypass the class non-trivial or deleted constructor +or copy assignment, violate const-correctness or encapsulation, or corrupt +the virtual table. Modifying the representation of such objects may violate +invariants maintained by member functions of the class. For example, the call +to @code{memset} below is undefined because it modifies a non-trivial class +object and is, therefore, diagnosed. The safe way to either initialize or +clear the storage of objects of such types is by using the appropriate +constructor or assignment operator, if one is available. @smallexample std::string str = "abc"; -memset (&str, 0, 3); +memset (&str, 0, sizeof str); @end smallexample The @option{-Wclass-memaccess} option is enabled by @option{-Wall}. +Explicitly casting the pointer to the class object to @code{void *} or +to a type that can be safely accessed by the raw memory function suppresses +the warning. @item -Wnon-virtual-dtor @r{(C++ and Objective-C++ only)} @opindex Wnon-virtual-dtor |