public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/25108]  New: gcc doesn't work for templates with `static const` members.
@ 2005-11-26 22:54 pluto at agmk dot net
  2005-11-26 23:02 ` [Bug c++/25108] " pinskia at gcc dot gnu dot org
  0 siblings, 1 reply; 2+ messages in thread
From: pluto at agmk dot net @ 2005-11-26 22:54 UTC (permalink / raw)
  To: gcc-bugs

#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


^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Bug c++/25108] gcc doesn't work for templates with `static const` members.
  2005-11-26 22:54 [Bug c++/25108] New: gcc doesn't work for templates with `static const` members pluto at agmk dot net
@ 2005-11-26 23:02 ` pinskia at gcc dot gnu dot org
  0 siblings, 0 replies; 2+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-11-26 23:02 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from pinskia at gcc dot gnu dot org  2005-11-26 23:02 -------
This is a dup of bug 14404.  The C++ code is illform with no diagnostic
required and the C++ compiler can (but does not have to) inline the constant
value in this case.

*** This bug has been marked as a duplicate of 14404 ***


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |DUPLICATE


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


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2005-11-26 23:02 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-11-26 22:54 [Bug c++/25108] New: gcc doesn't work for templates with `static const` members pluto at agmk dot net
2005-11-26 23:02 ` [Bug c++/25108] " pinskia at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).