User account creation filtered due to spam.

Bug 65790 - compilation error : receive std::index_sequence
Summary: compilation error : receive std::index_sequence
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.9.2
: P3 normal
Target Milestone: 5.2
Assignee: Not yet assigned to anyone
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2015-04-17 05:58 UTC by Akira Takahashi
Modified: 2015-07-09 14:21 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail: 4.8.3, 4.9.2, 5.0, 6.0
Last reconfirmed: 2015-04-17 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Akira Takahashi 2015-04-17 05:58:22 UTC
Compilation error follow code:

#include <iostream>
#include <utility>

void g(std::size_t a, std::size_t b, std::size_t c)
{
  std::cout << a << ", " << b << ", " << c << std::endl;
}

//template <class T, T... Seq>
//void f(std::integer_sequence<T, Seq...>) // OK
template <std::size_t... Seq>
void f(std::index_sequence<Seq...>) // NG
{
  g(Seq...);
}

int main()
{
  f(std::index_sequence<0, 1, 2>());
}


error message:
prog.cc: In function 'void f(std::index_sequence<Seq ...>)':
prog.cc:14:11: error: too few arguments to function 'void g(std::size_t, std::size_t, std::size_t)'
   g(Seq...);
           ^
prog.cc:4:6: note: declared here
 void g(std::size_t a, std::size_t b, std::size_t c)
      ^

I think this is compiler's issue, not libstdc++.
Comment 1 Jonathan Wakely 2015-04-17 08:09:06 UTC
Confirmed, Clang and EDG accept this:

extern "C" int printf(const char* ...);

namespace std
{
  typedef decltype(sizeof(0)) size_t;

  template<typename _Tp, _Tp... _Idx>
    struct integer_sequence
    {
      typedef _Tp value_type;
      static constexpr size_t size() { return sizeof...(_Idx); }
    };

  template<size_t... _Idx>
    using index_sequence = integer_sequence<size_t, _Idx...>;
}

void g(std::size_t a, std::size_t b, std::size_t c)
{
  printf("%zu, %zu, %zu\n", a, b, c);
}

template <std::size_t... Seq>
void f(std::index_sequence<Seq...>)
{
  g(Seq...);
}

int main()
{
  f(std::index_sequence<0, 1, 2>());
}
Comment 2 Paolo Carlini 2015-07-09 09:43:02 UTC
This is fixed for 5.2. Let's add the testcase and close the bug.
Comment 3 paolo@gcc.gnu.org 2015-07-09 09:51:41 UTC
Author: paolo
Date: Thu Jul  9 09:51:09 2015
New Revision: 225607

URL: https://gcc.gnu.org/viewcvs?rev=225607&root=gcc&view=rev
Log:
2015-07-09  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/65790
	* g++.dg/cpp0x/vt-65790.C: New.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/vt-65790.C
Modified:
    trunk/gcc/testsuite/ChangeLog
Comment 4 Paolo Carlini 2015-07-09 09:52:06 UTC
Done.
Comment 5 Akira Takahashi 2015-07-09 14:21:37 UTC
Thanks Paolo!!