Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

static constexpr member function in templated using expression not found

For the following code

#include <array>

template<unsigned MaxP, typename type>
struct kernel
{
  static constexpr unsigned max_pole(unsigned P)
  { return P>MaxP? MaxP:P; }

  template<unsigned P>
  using array = std::array<type,max_pole(P)>;          // wrong?

  template<unsigned P>
  static void do_something(array<P> const&, array<P>&);
};

gcc 4.7.0 (g++ -c -std=c++11) gives

error: ‘max_pole’ was not declared in this scope

Is this correct (behaviour of the compiler)? Note that if I resolve max_pole by replacing it with kernel::max_pole on the line indicated, it compiles fine.

EDIT Reported to bugzilla, accepted as bug c++/55992, see http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55992. Also occurs with gcc 4.7.x and 4.8.0.

like image 506
Walter Avatar asked Jan 15 '13 13:01

Walter


1 Answers

Your template compiles fine with Clang 3.2. I strongly believe it is a GCC bug (which is present in GCC 4.7.2 as well, btw). Change notes for GCC 4.8.0 do not seem to mention any such bugfix.

Also notice, that the compilation error disappears if you remove the declaration of do_something<>, which should not make any difference.

One more hint: while this template does not compile on GCC 4.7.2:

template<unsigned MaxP, typename type>
struct kernel
{
    static constexpr unsigned max_pole(unsigned P)
    { return P>MaxP? MaxP:P; }

     template<typename T>
     using array2 = int[max_pole(3)]; // ERROR!

     static void do_something(array2<int> const&, array2<int>&);
};

This template does compile:

template<unsigned MaxP, typename type>
struct kernel
{
    static constexpr unsigned max_pole(unsigned P)
    { return P>MaxP? MaxP:P; }

     // template<typename T>  <--- removed
     using array2 = int[max_pole(3)]; // OK

     static void do_something(array2 const&, array2&);
};

Since max_pole is in both cases an unqualified independent name, the lookup strategy should be the same in both cases, and it is not. To me, this qualifies it as a bug.

like image 130
Andy Prowl Avatar answered Sep 18 '22 11:09

Andy Prowl