public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/110536] New: Bogus -Wstringop-overflow warning in std::transform
@ 2023-07-03 18:47 eric.niebler at gmail dot com
  2023-07-03 19:53 ` [Bug tree-optimization/110536] " pinskia at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: eric.niebler at gmail dot com @ 2023-07-03 18:47 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 110536
           Summary: Bogus -Wstringop-overflow warning in std::transform
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: eric.niebler at gmail dot com
  Target Milestone: ---

Compile the following with -O3 -std=c++17 -Wall

<<<<<<BEGIN

#include <algorithm>
#include <cstdint>
#include <vector>

template <typename TypeParam, typename T>
std::vector<TypeParam>
make_type_param_vector(std::initializer_list<T> const& init_list) {
  // std::vector<T> input{init_list}; //uncomment to remove warning
  std::vector<TypeParam> vec(init_list.size());
  std::transform(std::cbegin(init_list), std::cend(init_list), std::begin(vec),
[](auto const& e) {
    if constexpr (std::is_unsigned_v<TypeParam>) { return
static_cast<TypeParam>(std::abs(e)); }
    return static_cast<TypeParam>(e);
  });
  return vec;
}

template <typename T>
void validate_A() {
  auto const input_column_valid_a = make_type_param_vector<uint8_t>({1, 0});
  auto const input_column_valid_b = make_type_param_vector<uint8_t>({0, 0});
  auto const input_column_valid_c = make_type_param_vector<T>({15, 16});
}

int main() {
  validate_A<float>();
  validate_A<double>();
  validate_A<int8_t>();
  validate_A<int16_t>();
  validate_A<int32_t>();
  validate_A<int64_t>();
  validate_A<uint8_t>();
  validate_A<uint16_t>();
  validate_A<uint32_t>();
}

<<<<<<END

Result:

In file included from
/opt/compiler-explorer/gcc-trunk-20230703/include/c++/14.0.0/algorithm:61,
                 from <source>:1:
In function '_OIter std::transform(_IIter, _IIter, _OIter, _UnaryOperation)
[with _IIter = const int*; _OIter = __gnu_cxx::__normal_iterator<unsigned
char*, vector<unsigned char, allocator<unsigned char> > >; _UnaryOperation =
make_type_param_vector<unsigned char, int>(const
std::initializer_list<int>&)::<lambda(const auto:1&)>]',
    inlined from 'std::vector<TypeParam> make_type_param_vector(const
std::initializer_list<T>&) [with TypeParam = unsigned char; T = int]' at
<source>:10:17:
/opt/compiler-explorer/gcc-trunk-20230703/include/c++/14.0.0/bits/stl_algo.h:4216:19:
warning: writing 1 byte into a region of size 0 [-Wstringop-overflow=]
 4216 |         *__result = __unary_op(*__first);
      |         ~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~


Demo:
https://godbolt.org/z/PKqfjr9cb

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

* [Bug tree-optimization/110536] Bogus -Wstringop-overflow warning in std::transform
  2023-07-03 18:47 [Bug c++/110536] New: Bogus -Wstringop-overflow warning in std::transform eric.niebler at gmail dot com
@ 2023-07-03 19:53 ` pinskia at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-07-03 19:53 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=106757

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Most likely a dup of bug 106757.

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

end of thread, other threads:[~2023-07-03 19:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-03 18:47 [Bug c++/110536] New: Bogus -Wstringop-overflow warning in std::transform eric.niebler at gmail dot com
2023-07-03 19:53 ` [Bug tree-optimization/110536] " pinskia 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).