This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/25108] New: gcc doesn't work for templates with `static const` members.


#ifdef EXPOSE_GCC_BUG

template <int n>
class pow3 {
public:
  static int const result = 3 * pow3<n-1>::result;
};
template <>
class pow3<0> {
public:
  static int const result = 1;
};

#else

template <int n>
class pow3 {
public:
  enum { result = 3 * pow3<n-1>::result };
};
template <>
class pow3<0> {
public:
  enum { result = 1 };
};

#endif

extern void foo(const int& x);
int main()
{
    foo(pow3<3>::result);
    return 0;
}

g++ power.cpp -o power -DEXPOSE_GCC_BUG

(...)
power.cpp: undefined reference to `pow3<(int)3>::result'
                                   ^^^^^^^^^^^^^^^^^^^^
(...)

gcc must instantiate pow3<3> and pass it by ref to foo().
[ this example becomes from the Nicolai M. Josuttis book. ]


-- 
           Summary: gcc doesn't work for templates with `static const`
                    members.
           Product: gcc
           Version: 4.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: pluto at agmk dot net
 GCC build triplet: *-linux
  GCC host triplet: *-linux
GCC target triplet: *-linux


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]