[Bug c++/111415] New: False positive array-bounds warning with -O3

2023-09-14 Thread daiw at gmx dot net via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111415

Bug ID: 111415
   Summary: False positive array-bounds warning with -O3
   Product: gcc
   Version: 13.2.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: daiw at gmx dot net
  Target Milestone: ---

Using g++ (GCC) 13.2.0,

the following minimal example:



std::vector foo(const std::vector& a)
{
if (a.size() < 2)
{
return a;
}
return a;
}

int main()
{
foo(std::vector({1}));
}



Produces a warning when trying to compile like so:


g++ -Wall -O3 main.cpp



Output:


In file included from /usr/local/include/c++/13.2.0/vector:62,
 from main.cpp:1:
In static member function 'static _Up* std::__copy_move<_IsMove, true,
std::random_access_iterator_tag>::__copy_m(_Tp*, _Tp*, _Up*) [with _Tp = const
int; _Up = int; bool _IsMove = false]',
inlined from '_OI std::__copy_move_a2(_II, _II, _OI) [with bool _IsMove =
false; _II = const int*; _OI = int*]' at
/usr/local/include/c++/13.2.0/bits/stl_algobase.h:506:30,
inlined from '_OI std::__copy_move_a1(_II, _II, _OI) [with bool _IsMove =
false; _II = const int*; _OI = int*]' at
/usr/local/include/c++/13.2.0/bits/stl_algobase.h:533:42,
inlined from '_OI std::__copy_move_a(_II, _II, _OI) [with bool _IsMove =
false; _II = __gnu_cxx::__normal_iterator >; _OI =
int*]' at /usr/local/include/c++/13.2.0/bits/stl_algobase.h:540:31,
inlined from '_OI std::copy(_II, _II, _OI) [with _II =
__gnu_cxx::__normal_iterator >; _OI = int*]' at
/usr/local/include/c++/13.2.0/bits/stl_algobase.h:633:7,
inlined from 'static _ForwardIterator
std::__uninitialized_copy::__uninit_copy(_InputIterator, _InputIterator,
_ForwardIterator) [with _InputIterator = __gnu_cxx::__normal_iterator >; _ForwardIterator = int*]' at
/usr/local/include/c++/13.2.0/bits/stl_uninitialized.h:147:27,
inlined from '_ForwardIterator std::uninitialized_copy(_InputIterator,
_InputIterator, _ForwardIterator) [with _InputIterator =
__gnu_cxx::__normal_iterator >; _ForwardIterator =
int*]' at /usr/local/include/c++/13.2.0/bits/stl_uninitialized.h:185:15,
inlined from '_ForwardIterator std::__uninitialized_copy_a(_InputIterator,
_InputIterator, _ForwardIterator, allocator<_Tp>&) [with _InputIterator =
__gnu_cxx::__normal_iterator >; _ForwardIterator =
int*; _Tp = int]' at
/usr/local/include/c++/13.2.0/bits/stl_uninitialized.h:373:37,
inlined from 'std::vector<_Tp, _Alloc>::vector(const std::vector<_Tp,
_Alloc>&) [with _Tp = int; _Alloc = std::allocator]' at
/usr/local/include/c++/13.2.0/bits/stl_vector.h:603:31,
inlined from 'std::vector foo(const std::vector&)' at
main.cpp:7:16:
/usr/local/include/c++/13.2.0/bits/stl_algobase.h:437:30: warning: 'void*
__builtin_memmove(void*, const void*, long unsigned int)' forming offset 4 is
out of the bounds [0, 4] [-Warray-bounds=]
  437 | __builtin_memmove(__result, __first, sizeof(_Tp) * _Num);
  | ~^~~

[Bug libstdc++/78991] std::sort and std::unique can not use std::function with clang++ -std=c++14

2017-01-04 Thread daiw at gmx dot net
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78991

Tobias  changed:

   What|Removed |Added

 Status|UNCONFIRMED |RESOLVED
 Resolution|--- |INVALID

--- Comment #3 from Tobias  ---
resolved as invalid. now posted here:
https://llvm.org/bugs/show_bug.cgi?id=31537

[Bug libstdc++/78991] std::sort and std::unique can not use std::function with clang++ -std=c++14

2017-01-04 Thread daiw at gmx dot net
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78991

--- Comment #2 from Tobias  ---
Thanks. The evidence you collected shows quite clear, that it probably is a
problem with clang.
So I now posted it here: https://llvm.org/bugs/show_bug.cgi?id=31537

[Bug libstdc++/78991] New: std::sort and std::unique can not use std::function with clang++ -std=c++14

2017-01-04 Thread daiw at gmx dot net
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78991

Bug ID: 78991
   Summary: std::sort and std::unique can not use std::function
with clang++ -std=c++14
   Product: gcc
   Version: unknown
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: libstdc++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: daiw at gmx dot net
  Target Milestone: ---

The following two minimal examples both compile with

clang++ -std=c++11 main.cpp

but do not with

clang++ -std=c++14 main.cpp


// example 1
#include 
#include 
#include 
int main()
{
  std::vector xs = {0,1,2};
  std::function<bool(int x, int y)> cmp = [](int x, int y)
{ return x < y; };
  std::sort(std::begin(xs), std::end(xs), cmp);
}


// example 2
#include 
#include 
#include 
int main()
{
  std::vector xs = {0,1,2};
  std::function<bool(int x, int y)> p = [](int x, int y)
{ return x == y; };
  std::unique(std::begin(xs), std::end(xs), p);
}


The error message looks like this:
In file included from
/usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.0/../../../../include/c++/5.4.0/algorithm:61:
In file included from
/usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.0/../../../../include/c++/5.4.0/bits/stl_algobase.h:71:
/usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.0/../../../../include/c++/5.4.0/bits/predefined_ops.h:123:31:
error: indirection requires pointer operand ('int' invalid)
{ return bool(_M_comp(*__it1, *__it2)); }


The used version is the default one from the package manager in Ubuntu 16.04:
clang++ --version
clang version 3.8.0-2ubuntu4 (tags/RELEASE_380/final)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

[Bug c++/78850] New: Parameter of returned generic lambda allegedly shadows parameter of free function

2016-12-18 Thread daiw at gmx dot net
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78850

Bug ID: 78850
   Summary: Parameter of returned generic lambda allegedly shadows
parameter of free function
   Product: gcc
   Version: unknown
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: daiw at gmx dot net
  Target Milestone: ---

Compiling the following code

template 
auto apply(X x, F f)
{
return f(x);
}

template 
auto add_value(Y y)
{
return [y](auto x)
{
return x + y;
};
}

int main()
{
apply(1, add_value(2));
}

with g++ (e.g. v. 5.4, but also newer ones) gives false shadow warnings:
https://godbolt.org/g/MMJ51o

$ g++ -Wshadow -Werror -std=c++14 shadow_test.cpp 
shadow_test.cpp: In instantiation of ‘add_value(Y)::<lambda(auto:1)> [with
auto:1 = int; Y = int]’:
shadow_test.cpp:4:13:   required from ‘auto apply(X, F) [with X = int; F =
add_value(Y) [with Y = int]::<lambda(auto:1)>]’
shadow_test.cpp:18:26:   required from here
shadow_test.cpp:10:22: error: declaration of ‘int x’ shadows a parameter
[-Werror=shadow]
 return [y](auto x)
  ^
shadow_test.cpp:2:14: note: shadowed declaration is here
 auto apply(X x, F f)
  ^
cc1plus: all warnings being treated as errors

Corresponding SO post:
http://stackoverflow.com/questions/41208811/parameter-of-returned-generic-lambda-allegedly-shadows-parameter-of-free-functio