This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/70111] New: Internal compiler error on constant enum access
- From: "tomasz at tomaszklak dot pl" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Sun, 06 Mar 2016 21:53:53 +0000
- Subject: [Bug c++/70111] New: Internal compiler error on constant enum access
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70111
Bug ID: 70111
Summary: Internal compiler error on constant enum access
Product: gcc
Version: 5.2.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: tomasz at tomaszklak dot pl
Target Milestone: ---
Created attachment 37881
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=37881&action=edit
example
The following code fails to compile with "internal compiler error: Segmentation
fault (program cc1plus)" with command "g++ -std=c++11 -Wall -Wextra -pedantic
-ftemplate-depth=100000 gccbug.cc"
struct Zero { enum { value = 0 }; };
template <typename Nat>
struct Next { enum { value = 1 + Nat::value }; };
using One = Next<Zero>;
using Two = Next<One>;
using Three = Next<Two>;
template <typename Lhs, typename Rhs>
struct Add;
template <typename Rhs>
struct Add<Zero, Rhs>
{
using type = Rhs;
};
template <typename Lhs, typename Rhs>
struct Add<Next<Lhs>, Rhs>
{
using type = Next<typename Add<Lhs, Rhs>::type>;
};
using Five = typename Add<Three, Two>::type;
using Six = typename Add<Three, Three>::type;
using v12 = typename Add<Six, Six>::type;
using v18 = typename Add<v12, Six>::type;
using v23 = typename Add<v18, Five>::type;
using v24 = typename Add<v12, v12>::type;
template <typename N>
struct Fib;
template<>
struct Fib<One> { using type = One; };
template<>
struct Fib<Two> { using type = One; };
template<typename Prev>
struct Fib<Next<Next<Prev>>> {
using type = typename Add<
typename Fib<Next<Prev>>::type,
typename Fib<Prev>::type>::type;
};
int main() {
// This compiles:
// using fib = typename Fib<v23>::type;
using fib = typename Fib<v24>::type;
(void) fib::value;
}
replacing fib assigment to Fib<v23> works fine. Similar behaviour is seen on
5.3.0 - https://goo.gl/rD2zy1