[Bug c++/96917] decltype(auto) variable initialized with lambda by-reference capture has incorrect type

2022-03-22 Thread gufideg at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96917

Guillaume Racicot  changed:

   What|Removed |Added

 CC||gufideg at gmail dot com

--- Comment #2 from Guillaume Racicot  ---
Seems this bug also apply to deduced return type:

template 
void foo();

void bar() {
int i;
auto l = []() -> decltype(auto) {
foo();
return i;
};
l();
foo();
}


Yield the assembly:

bar():
sub rsp, 8
callvoid foo()
add rsp, 8
jmp void foo()


Strangely, replacing the return expression to `return
static_cast(i);` seems to fix the behaviour.

[Bug c++/97470] New: ICE when using aggregate initialization of a particular layout with non trivial type

2020-10-17 Thread gufideg at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97470

Bug ID: 97470
   Summary: ICE when using aggregate initialization of a
particular layout with non trivial type
   Product: gcc
   Version: 10.2.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: gufideg at gmail dot com
  Target Milestone: ---

Here's a minimal case:

struct nontrivial {
nontrivial();
nontrivial(nontrivial const&);
long a;
};

struct foo {
nontrivial nt;
char b;
};

struct bar : foo {};

foo get_foo();

bar a{
get_foo()
};


Live ICE on compiler explorer: https://godbolt.org/z/WqnWY9

Changing `a` to something with a smaller size won't trigger the ICE.
Changing `b` to something with the same size of `a` won't trigger the ICE.
Changing `bar a{get_foo()}` to `bar a{foo{}}` won't trigger the ICE.
Swapping the members of foo will also make the ICE go away.

[Bug c++/91051] New: [9 Regression] Template conversion operator don't match when converting to constant rvalue reference

2019-07-01 Thread gufideg at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91051

Bug ID: 91051
   Summary: [9 Regression] Template conversion operator don't
match when converting to constant rvalue reference
   Product: gcc
   Version: 9.1.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: gufideg at gmail dot com
  Target Milestone: ---

The following code was compiling in older GCC version, but don't compile with
GCC 9.1:

struct probe {
template
operator T const&& ();
};

void frob(int const&) {}

int main() {
frob(probe()); // don't work with GCC 9.1
}

The expected result is the template conversion operator to rvalue reference to
constant to be called, then binding to the lvalue reference to constant.

This bug don't apply to non templated conversion operator:

struct probe {
operator int const&& ();
};

void frob(int const&) {}

int main() {
frob(probe()); // works under GCC 9.1
}

[Bug c++/86859] New: error: expansion pattern contains no parameter pack when a pack from introduced in a capture is used in decltype

2018-08-04 Thread gufideg at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86859

Bug ID: 86859
   Summary: error: expansion pattern contains no parameter pack
when a pack from introduced in a capture is used in
decltype
   Product: gcc
   Version: 8.2.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: gufideg at gmail dot com
  Target Milestone: ---

Here's the code snippet that triggers the bug:


int main() {
auto builder = [](auto b) {
return [b](auto... treeArgs) {
return [b, treeArgs...]()
-> decltype(b(treeArgs...)) {
return b(treeArgs...);
};
};
};
builder([]{});
}

GCC outputs a quite weird error message:

In instantiation of 'main():: [with auto:1 =
main()::]':
   required from here
error: expansion pattern '#'nontype_argument_pack' not supported by
dump_expr#' contains no parameter packs
 -> decltype(b(treeArgs...)) {
 ~^

This code compiles fine in clang.

Changing the `decltype()` for a `decltype(auto)` work around the bug:


int main() {
auto builder = [](auto b) {
return [b](auto... treeArgs) {
return [b, treeArgs...]()
-> decltype(auto) {
return b(treeArgs...);
};
};
};
builder([]{});
}

[Bug c++/86480] [8 Regression] error: parameter packs not expanded with '...' in a recursive variadic lambda

2018-07-11 Thread gufideg at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86480

--- Comment #2 from Guillaume Racicot  ---
Yes of course! I only added the `-std=c++17` flag.

Here's a live example: https://godbolt.org/g/p8KLfE

[Bug c++/86480] New: [8 Regression] error: parameter packs not expanded with '...' in a recursive variadic lambda

2018-07-11 Thread gufideg at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86480

Bug ID: 86480
   Summary: [8 Regression] error: parameter packs not expanded
with '...' in a recursive variadic lambda
   Product: gcc
   Version: 8.1.1
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: gufideg at gmail dot com
  Target Milestone: ---

The following code compiler with Clang and GCC 7.3:

#include 
#include 
#include 

template>>
struct tuple_sequence_helper;

template
struct tuple_sequence_helper> {
using type = std::tuple...>;
};

template
constexpr auto apply_sequence(F function) -> decltype(auto) {
return std::apply(function, typename tuple_sequence_helper>::type{});
}

template
struct drop_last_helper;

template
struct drop_last_helper> {
using type = std::tuple...>;
};

template
struct drop_last;

template
struct drop_last> :
drop_last_helper, std::make_index_sequence> {};

template
using drop_last_t = typename drop_last::type;

template
struct dropping_invoke_result_helper {};

template
struct dropping_invoke_result_helper, T,
std::enable_if_t>> {
using type = std::invoke_result_t;
};

template
struct dropping_invoke_result_helper,
std::index_sequence<0, S...>, std::enable_if_t>> :
dropping_invoke_result_helper>...>, std::make_index_sequence> {};


template
using dropping_invoke_result = dropping_invoke_result_helper, std::index_sequence_for>;

template
using dropping_invoke_result_t = typename dropping_invoke_result::type;

template
auto dropping_invoke(F&& f, Args&&... args) -> dropping_invoke_result_t {
auto recurse = [](auto self) {
return [self](auto&&... as) -> decltype(auto) { return self(self,
std::forward(as)...); };
};

auto drop = recurse([](auto self, auto&&... as) ->
dropping_invoke_result_t {
return apply_sequence([, ,
](auto... s) -> decltype(auto) {
auto pack =
std::forward_as_tuple(std::forward(as)...);

if constexpr (std::is_invocable_v...>) {
return std::invoke(
std::forward(f),
std::forward>(std::get(std::move(pack)))...
);
} else {
return self(self, std::forward(f),
std::forward>(std::get(std::move(pack)))...);
}
});
});

return drop(drop, std::forward(args)...);
}

int main() {
dropping_invoke(
[](auto a, int b){},
42.f, 12, 23
);
}

I have not succeeded to reduce it more, sorry for the large repro.

[Bug c++/85866] [8 Regression] too few arguments to function when sfinae on calling pointer to member function

2018-05-21 Thread gufideg at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85866

--- Comment #1 from Guillaume Racicot  ---
I tried some similar cases, and It seems it only happens when the expression
`(std::declval().*std::declval())()` is inside template parameters. In
the return type and normal function parameter it works as usual:

#include 

template
using void_t = void;

template
void_t boom(){}

struct Foo {
void bar(){}
};

int main() {
boom();
}

Live example: https://godbolt.org/g/vTE9Sr

[Bug c++/85866] New: [8 Regression] too few arguments to function when sfinae on calling pointer to member function

2018-05-21 Thread gufideg at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85866

Bug ID: 85866
   Summary: [8 Regression] too few arguments to function when
sfinae on calling pointer to member function
   Product: gcc
   Version: 8.1.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: gufideg at gmail dot com
  Target Milestone: ---

This code fails under GCC 8:

#include 

template
using void_t = void;

template().*std::declval())()
)>* = nullptr>
void boom(){}

struct Foo {
void bar(){}
};

int main() {
boom<Foo, decltype(::bar)>();
}

This particular code compiles on all other GCC versions since 4.7
It also compiles on all versions of clang since version 3.4

Live example: https://godbolt.org/g/viHnMn

[Bug c++/85743] New: Cannot call template member function inside a variadic lambda unless specifying `this`

2018-05-10 Thread gufideg at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85743

Bug ID: 85743
   Summary: Cannot call template member function inside a variadic
lambda unless specifying `this`
   Product: gcc
   Version: 8.1.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: gufideg at gmail dot com
  Target Milestone: ---

When using a particular pattern to expand a variadic template inside a member
function, `this->` need to be specified before calling other member functions.

Here is the most reduced repro I can come with at the moment:

#include 
#include 

template
struct tuple_sequence;

template
struct tuple_sequence<std::integer_sequence<I, S...>> {
using type = std::tuple<std::integral_constant<I, S>...>;
};

template
constexpr auto apply_sequence_for(F function) -> decltype(auto) {
return std::apply(function, typename
tuple_sequence<std::index_sequence_for>::type{});
}

template
struct Foo {
template
constexpr void boom(int i) const {}

constexpr auto foo(std::array<int, sizeof...(Ts)> data) const {
apply_sequence_for([this, ](auto... s) {
(boom(data[s]), ...);
});
}
};

int main() {
Foo<int, float, char> f;
f.foo({0, 1, 2});
}


Notice the particular expansion pattern `boom(data[s])`. The bug won't
trigger if the pattern is replaced by `boom(data[s])` or even
`boom(data[0])`.


This code compiles under Clang 6.0.0
Live example: https://godbolt.org/g/n6wMUS

[Bug c++/83476] Template argument deduction fails with reference template parameter

2018-05-03 Thread gufideg at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83476

Guillaume Racicot  changed:

   What|Removed |Added

   Keywords||rejects-valid
Version|7.3.1   |8.1.0
Summary|Template argument deduction |Template argument deduction
   |fails with reference auto   |fails with reference
   |template parameter  |template parameter

--- Comment #1 from Guillaume Racicot  ---
Still happen with GCC 8.1. It also happen with normal reference template
parameter.

Here's a simplified test case:

template struct foo {};

template
void deduce(foo) {}

extern int bar;
int bar;

int main() {
deduce(foo{});
}


This example compiles in MSVC and Clang. https://godbolt.org/g/kxKkb5

[Bug c++/85589] New: Non type template parameter should allow object with no linkage

2018-05-01 Thread gufideg at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85589

Bug ID: 85589
   Summary: Non type template parameter should allow object with
no linkage
   Product: gcc
   Version: 7.3.1
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: gufideg at gmail dot com
  Target Milestone: ---

Even though n4268 is marked as supported fully here:
https://gcc.gnu.org/projects/cxx-status.html, GCC does not yet support passing
the address or reference to an object with no linkage.

Such code should compile under C++17:

template<auto& v> struct foo {};

int main() {
static auto v = "str";
(void) foo {};
}

But fail with:

error: 'v' is not a valid template argument for type 'const char*&' because
object 'v' does not have linkage

 (void) foo {};
 ^

Such code compiles under clang 6.0.0.

Live example: https://godbolt.org/g/aXjDBg

[Bug c++/81700] Unresolved function type when taking address of operator() of generic lambda

2018-03-04 Thread gufideg at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81700

--- Comment #1 from Guillaume Racicot  ---
Still happen with 7.3 and trunk on godbolt: https://godbolt.org/g/xXUn1v

[Bug c++/83476] New: Template argument deduction fails with reference auto template parameter

2017-12-18 Thread gufideg at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83476

Bug ID: 83476
   Summary: Template argument deduction fails with reference auto
template parameter
   Product: gcc
   Version: 7.2.1
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: gufideg at gmail dot com
  Target Milestone: ---

As the title says, I have an auto reference template parameter which should be
deduced, but fails in this case:

constexpr auto lambda = []{};

template<auto& l>
struct Lambda {};

template<auto& l>
void test(Lambda) {}

int main() {
test(Lambda{});
}

The error is:

main.cpp: In function 'int main()':
main.cpp:10:26: error: no matching function for call to
'test(Lambda)'   
 test(Lambda{});
  ^
main.cpp:7:6: note: candidate: template<auto& l> void test(Lambda)
 void test(Lambda) {}
  ^~~~
main.cpp:7:6: note:   template argument deduction/substitution failed:
main.cpp:10:26: note:   couldn't deduce template parameter 'l'
 test(Lambda{});
  ^

The non-type template parameter should be deduced as any other non type
template parameter.

Here's this example at godbolt: https://godbolt.org/g/HV4Wpf

[Bug c++/81700] New: Unresolved function type when taking address of operator() of generic lambda

2017-08-03 Thread gufideg at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81700

Bug ID: 81700
   Summary: Unresolved function type when taking address of
operator() of generic lambda
   Product: gcc
   Version: 7.1.1
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: gufideg at gmail dot com
  Target Milestone: ---

Hi, have found this corner case when taking the address of operator() of a
generic lambda. This error only happen when using decltype with a function
defined as follow:

// Take a type, return that same type
template
T identity(T);

int main()
{
auto f = [](auto test) {};

using F = decltype(f);

// Error! Unresolved function type?
(void)decltype(identity(::operator())){};
}

However, taking the address of the lambda beforehand make GCC accept the code:

// Take a type, return that same type
template
T identity(T);

int main()
{
auto f = [](auto test) {};

using F = decltype(f);

// We simply add this line
(void)decltype(::operator()){};

// Compiles!
(void)decltype(identity(::operator())){};
}

Here's a live example: http://coliru.stacked-crooked.com/a/b7909605e2f882c9

Note that this bug don't happen with non-generic lambdas.

[Bug c++/81236] Crash when calling a template member function from generic lambda

2017-06-27 Thread gufideg at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81236

--- Comment #2 from Guillaume Racicot  ---
Created attachment 41640
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=41640=edit
CPP file that trigger the crash

[Bug c++/81236] Crash when calling a template member function from generic lambda

2017-06-27 Thread gufideg at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81236

--- Comment #1 from Guillaume Racicot  ---
Created attachment 41639
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=41639=edit
The compiler output crashing

[Bug c++/81236] New: Crash when calling a template member function from generic lambda

2017-06-27 Thread gufideg at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81236

Bug ID: 81236
   Summary: Crash when calling a template member function from
generic lambda
   Product: gcc
   Version: 7.1.1
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: gufideg at gmail dot com
  Target Milestone: ---

This causes current G++ (7.1.1) to crash:

#include 

template 
constexpr void for_sequence(std::integer_sequence<T, S...>, F&& f) {
using unpack_t = int[];
(void)unpack_t{(static_cast(f(std::integral_constant<T, S>{})),
0)..., 0};
}

template
struct MyType {
void crash() {
   
for_sequence(std::make_index_sequence<std::tuple_size::value>{}, [&](auto
i){
make_crash(); // Line (1)
});
}

template
void make_crash() {}
};

int main() {
MyType<std::tuple<int, double, double, const char*>> test;

test.crash();
}

Commenting line marked as `(1)` makes the code compile.

This code is valid and compiles under clang (3.8.0)

[Bug c++/80795] New: Cannot take the address of call operator of a variadic lambda when parameter pack length differs from 1

2017-05-16 Thread gufideg at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80795

Bug ID: 80795
   Summary: Cannot take the address of call operator of a variadic
lambda when parameter pack length differs from 1
   Product: gcc
   Version: 7.1.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: gufideg at gmail dot com
  Target Milestone: ---

Hi there, I stumble across this error:

int main() {
auto test = [](auto, auto, auto...) {};
auto ash = (test)::operator()<int, int>;
}

In this case, I expect the pointer to the function to be the one this
expression would call:

[](auto, auto, auto...){}(1, 1);

Leaving the parameter pack empty.
But it fails with this error:

> main.cpp: In function 'int main()':
> main.cpp:3:30: error: unable to deduce 'auto' from '& operator()<int, int>'
>   auto ash = (test)::operator()<int, int>;
>   ^~~~
> main.cpp:3:30: note:   couldn't deduce template parameter 'auto'

The same happen when Sending two parameter in the pack:

int main() {
auto test = [](auto, auto, auto...) {};
auto ash = (test)::operator()<int, int, int, int>;
}

Note that taking the pointer when exactly one parameter fits in the pack, it
compiles fine:

int main() {
auto test = [](auto, auto, auto...) {};
auto ash = (test)::operator()<int, int, int>;
}

All of the example above compiles fine under clang.

[Bug c++/79865] New: Crash when calling member function with template parameter from generic lambda

2017-03-04 Thread gufideg at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79865

Bug ID: 79865
   Summary: Crash when calling member function with template
parameter from generic lambda
   Product: gcc
   Version: 6.3.1
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: gufideg at gmail dot com
  Target Milestone: ---

Created attachment 40882
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=40882=edit
GCC Version

Inputting this code makes GCC crash on the call of `crashIt`:

#include 

struct Subject {
using Types = std::tuple<int, double>;
};

struct Test {
template
void test() {
test(std::make_index_sequence<std::tuple_size::value>{});
}

template
void test(std::index_sequence) {
int unpack[] = {(static_cast([&](auto i){
using Type = std::tuple_element_t<i, typename T::Types>;

crashIt(); // Here's the crash!

}(std::integral_constant<std::size_t, S>{})), 0)..., 0};

(void)unpack;
}

template
void crashIt() {}
};

int main(){
Test{}.test();
}

Not using a lambda in the expansion of `S` make the code compile.
This code compile fine under Clang 3.9.1.

The complete GCC version is in the attachement.