[Bug c++/95004] New: Static array of base classes member pointers

2020-05-08 Thread vince.rev at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95004

Bug ID: 95004
   Summary: Static array of base classes member pointers
   Product: gcc
   Version: 10.1.1
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: vince.rev at gmail dot com
  Target Milestone: ---

Created attachment 48480
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=48480&action=edit
Example of bug with base member pointers

Consider the following code in std=c++17:
==
#include 
#include 

template  struct base {
std::size_t value;
};

struct derived: base<0>, base<1> {
using pointer_type = std::size_t derived::*;
static constexpr std::array members{{
&derived::base<0>::value, 
&derived::base<1>::value
}};
constexpr std::size_t& operator[](std::size_t i) noexcept {
return this->*(members[i]);
}
constexpr const std::size_t& operator[](std::size_t i) const noexcept {
return this->*(members[i]);
}
};

int main(int, char**) {
derived x{42, 84};
std::cout << sizeof(base<0>) + sizeof(base<1>) << " " << sizeof(derived);
std::cout << std::endl;
std::cout << x[0] << " " << x[1]; // should display 42 84 but display 42 42
std::cout << std::endl;
return 0;
}
==

It creates a templated structure "base" with a data member "value", and a
structure "derived" that inherits from several specializations of "base". The
code tries to access the "value" of one or the other "base" class depending on
an index provided at runtime. The provided code does not achieve this, and
always returns the value of the first "base".

The problem is also described here:
https://stackoverflow.com/questions/61675172/accessing-members-of-base-classes-in-the-derived-class-through-runtime-indexing

And clang produces the correct output:
https://godbolt.org/z/c72xLa

The bug was successfully reproduced on all version of gcc from 7.1 to 10.1

[Bug c++/95036] New: ICE with variadic type/nttp template templates

2020-05-10 Thread vince.rev at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95036

Bug ID: 95036
   Summary: ICE with variadic type/nttp template templates
   Product: gcc
   Version: 10.1.1
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: vince.rev at gmail dot com
  Target Milestone: ---

Created attachment 48497
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=48497&action=edit
ICE with variadic type/nttp template templates

The following code in std=c++17 (I couldn't make it smaller because I don't
know where the bug is coming from) compiles correctly with gcc 7 and 8, but
fails with gcc 9 and 10. Link to godbolt: https://godbolt.org/z/x_66lB


#include 
#include 
#include 

template  class Template>
struct base {
template  class, class = void>
struct is_same_template: std::false_type {};
template 
struct is_same_template: std::true_type {};
template <
template  class X,
class = std::enable_if_t::value>
>
constexpr void function() const noexcept {};
};

template  class... Templates>
struct derived: base... {
using base::function...;
};

int main(int, char**) {
derived x;
x.function();
}


The error message is :

gcc-ice-2020-05-10.cpp: In substitution of 'template > class X, class> constexpr void
base::function >() const
[with X = std::array;  = ]':
gcc-ice-2020-05-10.cpp:25:28:   required from here
gcc-ice-2020-05-10.cpp:10:12: internal compiler error: in tsubst, at
cp/pt.c:14592
   10 | struct is_same_template: std::true_type {};
  |^
Please submit a full bug report,
with preprocessed source if appropriate.
See  for instructions.


[Bug c++/54323] New: Friend function declaration not correctly identified with CRTP + enable_if

2012-08-19 Thread vince.rev at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54323

 Bug #: 54323
   Summary: Friend function declaration not correctly identified
with CRTP + enable_if
Classification: Unclassified
   Product: gcc
   Version: 4.7.1
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
AssignedTo: unassig...@gcc.gnu.org
ReportedBy: vince@gmail.com


Created attachment 28051
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=28051
.cpp bug example

The following example involving a friend function in a Curiously Recurring
Template Pattern base class with an enable_if default template argument is not
working :

// 
#include 

// Base class definition
template class CRTP, typename T> class Base
{
// Friend function declaration
public:
template class CRTP0, typename T0, class>
friend int func(const Base& rhs);

// Protected test variable
protected:
 int n;
};

// Friend function definition
template class CRTP0, typename T0,
class = typename std::enable_if::type>
int func(const Base& rhs)
{
return rhs.n;
}

// Derived class definition
template class Derived : public Base {};

// Main
int main()
{
Derived x;
func(x);
return 0;
}
// 

g++ (tested with 4.6.1, 4.6.2 and 4.7.1) seems not to be able to match the
definition with the declaration of the function and return the following error
:
"int Base::n' is protected"


[Bug c++/55223] New: [C++11] Default lambda expression of a templated class member

2012-11-06 Thread vince.rev at gmail dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55223



 Bug #: 55223

   Summary: [C++11] Default lambda expression of a templated class

member

Classification: Unclassified

   Product: gcc

   Version: 4.7.2

Status: UNCONFIRMED

  Severity: major

  Priority: P3

 Component: c++

AssignedTo: unassig...@gcc.gnu.org

ReportedBy: vince@gmail.com





The following example returns a compiler error "internal compiler error : in

tsubst_copy, at cp/pt.c:11354". It occurs when the default std::function of a

templated class member is used :



//---

#include 

#include 



template struct C

{

static T test(std::function f = [](int i){return i;})

{return f(42);}

};



int main(int argc, char* argv[])

{

C::test(); // ERROR = internal compiler error : in tsubst_copy, at

cp/pt.c:11354

C::test([](int i){return i;}); // OK

return 0;

}

//---



Tested on GCC 4.6.3 and 4.7.2.


[Bug c++/57846] New: CRTP, templates, metaprogramming, forwarding and static member

2013-07-07 Thread vince.rev at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57846

Bug ID: 57846
   Summary: CRTP, templates, metaprogramming, forwarding and
static member
   Product: gcc
   Version: 4.8.1
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: vince.rev at gmail dot com

This code (I could not find a simpler example) does not compile under g++ for
some obscure reasons (tested with 4.8.1 and 4.7.2) (see the related discussion
on stack overflow here :
http://stackoverflow.com/questions/17515079/crtp-templates-metaprogramming-forwarding-and-static-member-a-bug-in-g-4-8):

-
#include 
#include 
#include 
#include 
#include 

template  struct Base
{
template  >::type> inline const Type&
get() const {return std::get(data);}
template  >::type> inline Crtp& set(const
Type& value) {std::get(data) = value; return static_cast(*this);}
std::tuple data;
};

template  struct Derived : public
Base, std::array>
{
template , std::array>>().template
get<0>(std::declval()...))> inline Template test(Args&&... args) const
{return this->template get<0>(std::forward(args)...);} 
template , std::array>>().template
set<0>(std::declval()...))> inline Derived& test(Args&&...
args) {return this->template set<0>(std::forward(args)...);} 
static void check() {Derived derived;
std::cout< derived; std::cout<::check(); // Not working: error: no match for
‘operator[]’ (operand types are ‘Derived’ and ‘int’)
return 0;
}

-

[Bug c++/57846] CRTP, templates, metaprogramming, forwarding and static member

2013-07-16 Thread vince.rev at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57846

--- Comment #1 from Vincent  ---
Apparently, this is also a bug in the last version (4.9):
http://stackoverflow.com/questions/17515079/crtp-templates-metaprogramming-forwarding-and-static-member-a-bug-in-g-4-8


[Bug c++/84489] New: Non-type template parameter dependency

2018-02-20 Thread vince.rev at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84489

Bug ID: 84489
   Summary: Non-type template parameter dependency
   Product: gcc
   Version: 7.3.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: vince.rev at gmail dot com
  Target Milestone: ---

Created attachment 43475
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=43475&action=edit
Example code of the bug

Consider the following code in C++11.
=
#include 

template > 1)>
constexpr T f0() {return 0;}

template > 1)>
constexpr T f1() {return 0;}

int main()
{
f0(); // No bug
f1(); // Bug here
return 0;
}
=

It compiles well under g++ 4.7, 4.8, 4.9, 5.X but fails to compile under 6.X
and 7.X. It also compiles well under clang. The returned error is:

=
gcc_bug_template_bool.cpp: In function 'int main()':
gcc_bug_template_bool.cpp:12:8: error: no matching function for call to 'f1()'
 f1();
^
gcc_bug_template_bool.cpp:7:13: note: candidate: template
constexpr T f1()
 constexpr T f1() {return 0;}
 ^~
gcc_bug_template_bool.cpp:7:13: note:   template argument
deduction/substitution failed:
gcc_bug_template_bool.cpp:6:49: error: invalid use of template type parameter
'T'
 template > 1)>
  ~~~^
gcc_bug_template_bool.cpp:6:53: error: could not convert template argument
'' from '' to 'bool'
 template > 1)>
=

[Bug libstdc++/84690] New: std::is_invocable not working for ambiguous calls

2018-03-03 Thread vince.rev at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84690

Bug ID: 84690
   Summary: std::is_invocable not working for ambiguous calls
   Product: gcc
   Version: 7.2.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: libstdc++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: vince.rev at gmail dot com
  Target Milestone: ---

Consider the following code:
==
// Preamble
#include 
#include 

// A base class
template 
struct base {void operator()(T){};};

// Two derived classes inheriting from the same base classes
template 
struct derived1: base... {using base::operator()...;};
template 
struct derived2: base... {using base::operator()...;};

// A class inheriting from both derived1 and derived2
template 
struct functor: derived1, derived2 {
using derived1::operator();
using derived2::operator();
};

// Main function
int main() {
std::cout << std::is_invocable_v, int> << "\n";
std::cout << std::is_invocable_v, float> << "\n";
std::cout << std::is_invocable_v, char> << "\n";
return 0;
}
==

The std::is_invocable type trait from the standard library fails to detect that
the first call in the main function is ambiguous. The program returns 1, 1, 1
instead of 0, 1, 1. This seems to be related to
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84689 and to
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80245.

[Bug c++/55724] New: Default type of a template value is not working

2012-12-17 Thread vince.rev at gmail dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55724



 Bug #: 55724

   Summary: Default type of a template value is not working

Classification: Unclassified

   Product: gcc

   Version: 4.7.2

Status: UNCONFIRMED

  Severity: blocker

  Priority: P3

 Component: c++

AssignedTo: unassig...@gcc.gnu.org

ReportedBy: vince@gmail.com





The following code does not compile with g++ 4.7 :





template struct S {};

template void f(S) {}

int main() { S<1> s; f(s); }





(source : http://stackoverflow.com/q/13915835/882932)


[Bug c++/55931] New: Constexpr member function inside a static member is not working

2013-01-09 Thread vince.rev at gmail dot com

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55931

 Bug #: 55931
   Summary: Constexpr member function inside a static member is
not working
Classification: Unclassified
   Product: gcc
   Version: 4.7.2
Status: UNCONFIRMED
  Severity: major
  Priority: P3
 Component: c++
AssignedTo: unassig...@gcc.gnu.org
ReportedBy: vince@gmail.com


The call of a constexpr member of a class into a static member of the same
class is not working. This is illustrated by the following code:
(tested on g++ 4.7.1 and 4.7.2, but it may also affect g++ 4.8)

---
#include 
#include 

template
class Test
{
public:
constexpr Test(const Type val) : _value(val) {}
constexpr Type get() const {return _value;}
static void test()
{
static constexpr Test x(42);
std::integral_constant i; // This is not working
std::cout< x(42);
std::integral_constant i; // This is working
std::cout<::test();
return 0;
}
---

which produces the following error:

---
main.cpp: In static member function ‘static void Test::test()’:
main.cpp:13:48: erreur: invalid use of ‘Test::get’ to form a
pointer-to-member-function
main.cpp:13:48: note:   a qualified-id is required
main.cpp:13:48: erreur: could not convert template argument
‘x.Test::get()’ to ‘int’
main.cpp:13:51: erreur: invalid type in declaration before ‘;’ token
---


[Bug c++/70505] New: Constexpr failure when template type specified

2016-04-01 Thread vince.rev at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70505

Bug ID: 70505
   Summary: Constexpr failure when template type specified
   Product: gcc
   Version: 6.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: vince.rev at gmail dot com
  Target Milestone: ---

This bug seems to affect g++ 4.9, 5.1, 5.2, 5.3 and 6.0 (tested on
gcc.godbolt.org), while the same code compiles under g++ 4.7.3, 4.8.1 and 4.8.2
as well as under clang. 

The code is the following:
=
#include 

template  
struct s
{
template  
static constexpr T f1(const T x) {return x;}
template (sizeof(T))> 
static constexpr T f2(const T x) {return x;} 
static void f() {s::f2(42);}
};

int main()
{
s::f();
}
=

and the error is:

=
main.cpp:10:39: error: no matching function for call to ‘s::f2(int)’
 static void f() {s::f2(42);}
   ^
main.cpp:9:28: note: candidate: template > static
constexpr T s::f2(T) [with T = T; T  = ; X = int]
 static constexpr T f2(const T x) {return x;} 
^
main.cpp:9:28: note:   template argument deduction/substitution failed:
main.cpp:8:47: error: expression ‘f1’ is not a constant-expression
 template (sizeof(T))> 
   ^
main.cpp:8:47: note: in template argument for type ‘int’ 
=

The bug does not show up when the line n°8 is modified to:

=
#include 

template  
struct s
{
template  
static constexpr T f1(const T x) {return x;}
template  
static constexpr T f2(const T x) {return x;} 
static void f() {s::f2(42);}
};

int main()
{
s::f();
}
=

[Bug c++/80739] New: Accessing value of X through a Y glvalue in a constant expression

2017-05-14 Thread vince.rev at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80739

Bug ID: 80739
   Summary: Accessing value of X through a Y glvalue in a constant
expression
   Product: gcc
   Version: 6.2.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: vince.rev at gmail dot com
  Target Milestone: ---

Created attachment 41352
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=41352&action=edit
Example of the bug

Consider the following valid code in C++14 (compiles without problem under
clang):
// ==
//
#include 
template  struct element {
constexpr element() noexcept: x0(0), x1(0), x2(0), x3(0) {}
T x0; int x1, x2, x3;
};
template  struct container {
constexpr container() noexcept: data() {data = element();}
element data;
};
template  constexpr bool test() {
return (container(), true);
}
int main() {
constexpr bool tmp0 = test(); // works
constexpr bool tmp1 = test(); // fails
return tmp0 && tmp1;
}
// ==
//

Compilation fails under g++-5 (g++-5 (Ubuntu 5.4.1-2ubuntu1~16.04) 5.4.1
20160904) with the following message:
## --
##
gcc_compiler_error.cpp: In function ‘int main()’:
gcc_compiler_error.cpp:16:44:   in constexpr expansion of ‘test()’
gcc_compiler_error.cpp:16:45:   in constexpr expansion of ‘container()’
gcc_compiler_error.cpp:16:45: internal compiler error: unexpected expression
‘*(container*)this’ of kind mem_ref
 constexpr bool tmp1 = test(); // fails
 ^
Please submit a full bug report,
with preprocessed source if appropriate.
See  for instructions.
## --
##

Compilation fails under g++-6 (g++-6 (Ubuntu 6.2.0-3ubuntu11~16.04) 6.2.0
20160901) with the following message:
## --
##
gcc_compiler_error.cpp: In function ‘int main()’:
gcc_compiler_error.cpp:16:44:   in constexpr expansion of ‘test()’
gcc_compiler_error.cpp:16:45:   in constexpr expansion of ‘container()’
gcc_compiler_error.cpp:16:45: error: accessing value of ‘’ through a
‘char [20]’ glvalue in a constant expression
 constexpr bool tmp1 = test(); // fails
 ^
## --
##

Other versions may be affected (not tested).

[Bug c++/78701] New: Template deduction, dependent template and conversion to bool failure

2016-12-06 Thread vince.rev at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78701

Bug ID: 78701
   Summary: Template deduction, dependent template and conversion
to bool failure
   Product: gcc
   Version: 6.1.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: vince.rev at gmail dot com
  Target Milestone: ---

The following code fails to compile on g++ 6.1, 6.2, and 7 (and I guess on g++
6.0):
==
#include 
template  T f(T x) {return T();}
int main(int argc, char* argv[]) {return f(42);}
==

It returns the following error:
==
test_bug.cpp: In function ‘int main(int, char**)’:
test_bug.cpp:3:46: error: no matching function for call to ‘f(int)’
 int main(int argc, char* argv[]) {return f(42);}
  ^
test_bug.cpp:2:49: note: candidate: template T f(T)
 template  T f(T x) {return T();}
 ^
test_bug.cpp:2:49: note:   template argument deduction/substitution failed:
test_bug.cpp:2:42: error: invalid use of template type parameter ‘T’
 template  T f(T x) {return T();}
~~^~~
test_bug.cpp:2:44: error: could not convert template argument ‘’ to ‘bool’
 template  T f(T x) {return T();}
^
==

[Bug c++/78701] Template deduction, dependent template and conversion to bool failure

2016-12-06 Thread vince.rev at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78701

--- Comment #1 from Vincent  ---
Addition:
==
#include 
template  T f(T x) {return T();}
int main(int argc, char* argv[]) {return f(42);}
==
(without the N + 1)
returns:
==
test_bug.cpp: In substitution of ‘template T f(T) [with T
= int; T N = ; bool B = ]’:
test_bug.cpp:3:46:   required from here
test_bug.cpp:2:40: internal compiler error: unexpected expression ‘N’ of kind
template_parm_index
 template  T f(T x) {return T();}
^
Please submit a full bug report,
with preprocessed source if appropriate.
See  for instructions.
==

[Bug c++/78701] [6/7 Regression] ICE: unexpected expression N of kind template_parm_index

2016-12-06 Thread vince.rev at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78701

--- Comment #3 from Vincent  ---
I am compiling with:
g++ test_bug.cpp -o test_bug
g++ -std=c++11 test_bug.cpp -o test_bug
g++ -std=c++14 test_bug.cpp -o test_bug
and it fails in the 3 cases.

[Bug c++/60130] New: Sorry, unimplemented: mangling argument_pack_select

2014-02-09 Thread vince.rev at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60130

Bug ID: 60130
   Summary: Sorry, unimplemented: mangling argument_pack_select
   Product: gcc
   Version: 4.8.2
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: vince.rev at gmail dot com

Hello.

Consider the following code in C++11:
--
#include 

template 
S f1(F f, T... x)
{
return std::get<0>(std::make_tuple(f(x)...));
}

template 
int f2(const T... x)
{
return std::get<0>(std::make_tuple(f1([](int n){return n;}, x)...));
}

int main()
{
return f2(42);
}
--

Under g++ 4.8.1 and 4.8.2 (I have not tried 4.9.0), it produces the following
compilation error: "sorry, unimplemented: mangling argument_pack_select". This
code compiles without any error under intel and clang.