4

I found this example on http://en.cppreference.com/w/cpp/language/partial_specialization

template <int I, int J, int K> struct B {};
template <int I> struct B<I, I*2, 2> {};  // OK: first parameter is deducible

I have errors while compiling it with -std=c++11 and -std=c++14

How to compile this? Or maybe example is wrong?

error: template argument ‘(I * 2)’ involves template parameter(s)
 template <int I> struct B<I, I*2, 2> {};  // OK: first parameter is deducible
peterSweter
  • 633
  • 6
  • 23

1 Answers1

6

This is a recent language change, and even the current releases of several compilers don't implement it yet. It's CWG issue 1315, which lists the status as "tentatively ready", though according to @bogdan in the comments, the change has already been accepted into the standard. Prior to that change, it was invalid for exactly the reason that your compiler shows in its error message.

Changing GCC's behaviour is on the GCC bug tracker as PR 77781.

  • 1
    The status that appears in the issues list is out of date. The resolution for CWG1315 was adopted into the working draft as part of P0263. The wording has been subsequently modified by P0127 (declaring non-type template parameters with `auto`), but the end result in this case is the same. Since it's (originally) a resolution for a DR, it will be applied retroactively to C++11 and 14 modes of compilers when implemented. – bogdan Feb 04 '17 at 15:27
  • @bogdan Thanks. I'm not sure about the status of working drafts, I don't know if that merely means it applies to what will become C++17, or if it applies as a C++14 DR (as cppreference's text suggests). At any rate, re-worded and mentioned your comment. –  Feb 04 '17 at 15:32