[Bug c++/82930] [C++17] ICE: in is_normal_capture_proxy, at cp/lambda.c:288 with structured binding in a lambda function with auto typed arguments

2018-02-07 Thread hotguest1 at hotmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82930

sandthorn  changed:

   What|Removed |Added

 CC||hotguest1 at hotmail dot com

--- Comment #3 from sandthorn  ---
I also confirm this on GCC 8.0.1 20180206,
but GCC 7.3 seems okey with code below.

https://godbolt.org/g/kwDaVE

auto lam = [](auto structured_bindable){ // also error with auto&
   auto [first,second] = structured_bindable; // also error with
auto&
   auto test_access = first;
};


g++ (GCC-Explorer-Build) 8.0.1 20180206 (experimental) 
: In lambda function:
:3:35: internal compiler error: in is_normal_capture_proxy, at
cp/lambda.c:288
auto test_access = first;
   ^
mmap: Invalid argument

[Bug c++/87322] New: [GCC 8.1+] GCC fails to parse captured lambda of 2nd inner lambda if the captured lambda has "," (having 2 arguments)

2018-09-15 Thread hotguest1 at hotmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87322

Bug ID: 87322
   Summary: [GCC 8.1+] GCC fails to parse captured lambda of 2nd
inner lambda if the captured lambda has "," (having 2
arguments)
   Product: gcc
   Version: unknown
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: hotguest1 at hotmail dot com
  Target Milestone: ---

Compiler thinks ',' in
inner_func2 =  [] (auto a, auto b) { return a + b; }
is capture separation.



Reproducing code: https://godbolt.org/z/3h1ByQ

#include 
#include 

int main()
{
  constexpr std::array,3> my_mat { 
 { { 1., 1. },
   { 1., 1. },
   { 1., 1. }, }
  };

  std::for_each(my_mat.begin(), my_mat.end(), [
  inner_func =  [] (auto a, auto b) { return a + b; } ](auto& row) {
std::for_each(row.begin(), row.end(), [&,
  inner_func2 =  [] (auto a, auto b) { return a + b; } ]
  (const double&) {
return;
});
  }); 

}


Error:

: In instantiation of 'main():: [with auto:3 = const
std::array]':

/opt/compiler-explorer/gcc-8.1.0/include/c++/8.1.0/bits/stl_algo.h:3882:5:  
required from '_Funct std::for_each(_IIter, _IIter, _Funct) [with _IIter =
const std::array*; _Funct = main()::]'

:19:4:   required from here

:15:58: internal compiler error: Segmentation fault

   inner_func2 =  [] (auto a, auto b) { return a + b; } ]

  ^

Please submit a full bug report,

with preprocessed source if appropriate.

See <https://gcc.gnu.org/bugs/> for instructions.

Compiler returned: 1

[Bug c++/84930] New: Brace-closed initialization of cstring (i.e."abcdefghi") to coresponding aggregate types fails in certain situation

2018-03-18 Thread hotguest1 at hotmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84930

Bug ID: 84930
   Summary: Brace-closed initialization of cstring
(i.e."abcdefghi") to coresponding aggregate types
fails in certain situation
   Product: gcc
   Version: unknown
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: hotguest1 at hotmail dot com
  Target Milestone: ---

We can do this in both GCC and clang

std::array, 2> arr_from_cstr1{{
{{"abcdefghi"}}, {{"abcdefghi"}}
}};

std::array arr_from_cstr2{{
{"abcdefghi"}, {"abcdefghi"}
}};

std::vector > vec_from_direct{{
{{ 'a','b','c','d','e','f','g','h','i','\0' }},
{{ 'a','b','c','d','e','f','g','h','i','\0' }}
}};

std::vector vec_from_ctor{{
std::array{ {"abcdefghi"} },
std::array{ {"abcdefghi"} }
}};

We can't do this in GCC but can do in clang

std::vector > vec_from_ctr1{{
{{"abcdefghi"}}, {{"abcdefghi"}}
}};

struct A {
  std::array x; 
  A(std::array arr) : x(arr) {}
};
A struct_from_ctr1{ {{"abcdefghi"}} };

You may see the error details in CE (tested with gcc 7.3):
https://godbolt.org/g/zV6dHd

I'm sorry that I can't describe the scenario good enough.

[Bug c++/97640] New: GCC doesn't optimize-out outside-affecting lambdas within y-combinator while clang does.

2020-10-30 Thread hotguest1 at hotmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97640

Bug ID: 97640
   Summary: GCC doesn't optimize-out outside-affecting lambdas
within y-combinator while clang does.
   Product: gcc
   Version: unknown
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: hotguest1 at hotmail dot com
  Target Milestone: ---

Suppose we have a y-combinator, so that we can write lambdas in recursive
fashion.

template 
struct y_combinator {
F f;
template 
constexpr decltype(auto) operator()(Ts&&... ts) const { return
f(std::ref(*this), std::forward(ts)...); }

template 
constexpr decltype(auto) operator()(Ts&&... ts) { return
f(std::ref(*this), std::forward(ts)...); }
};


Let's have a constexpr-qualified lambda

auto sum = y_combinator{[&](auto self,int a,int b,int res = 0) mutable {
if (a>b) {
  return res;
}
res += a;
return self(a+1,b,res);
}};

This lambda is constexpr-qualified.
So both gcc and clang do optimize-out all the things in the name of constexpr
expansion.
https://compiler-explorer.com/z/qx4MGE

==

Let's try an outside-affecting lambda

auto sum = y_combinator{[&,res=0](auto self,int a,int b) mutable {
if (a>b) {
  return res;
}
res += a;
return self(a+1,b);
}};

This non-constexpr-qualified lambda is optimized-out in clang but in gcc it is
not.
https://compiler-explorer.com/z/hPGWod

[Bug c++/97640] GCC doesn't optimize-out outside-affecting lambdas within y-combinator while clang does.

2020-10-30 Thread hotguest1 at hotmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97640

--- Comment #1 from sandthorn  ---
The y-combinator implementation is from Barry's and Mathemagician's answer on
SO.
https://stackoverflow.com/a/40873657/6370128