public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/39777]  New: Template behaviour when a template class has a member template class deriving from its container
@ 2009-04-15 15:18 pietro dot braione at polimi dot it
  2009-04-15 15:21 ` [Bug c++/39777] " pietro dot braione at polimi dot it
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: pietro dot braione at polimi dot it @ 2009-04-15 15:18 UTC (permalink / raw)
  To: gcc-bugs

The following C++ program aims to calculate the sum of some ints at compile
time:

//BEGINS SUM.CPP
template<int N>
class Sum { 
public:
    enum { val = N };
    template<int K>
    class Inc : public Sum<val + K> { };
};

int main() {
  return(Sum<2>::Inc<3>::Inc<6>::Inc<4>::val);
}
//ENDS SUM.CPP

Now GCC produces:

$ g++ sum.c
$ ./a.out ; echo $? 
6

More generally, every Sum<x_0>::Inc<x_1>::Inc<x_2>::...::Inc<x_n>::val is
always expanded to just x_0 + x_n. When compiled with Digital Mars C++ the same
example produces 15 as output (more generally, produces the sum of all the
provided integers as I would expect). 
Which is the right behaviour?

---
$ g++ -v
Using built-in specs.
Target: x86_64-unknown-linux-gnu
Configured with: ./gcc-4.3.3/configure
Thread model: posix
gcc version 4.3.3 (GCC)

I checked this example against a barebone, fresh 4.3.3 build with just gcc-core
and gcc-g++, gmp-4.2.1 and mpfr-2.3.0, all downloaded from a gcc mirror, fully
boostrapped with no options on a Gentoo distribuition. The same behaviour
occurs with a 4.1.2 GCC version on Gentoo and with a 3.4.4 GCC version on
Cygwin. The Digital Mars C++ compiler version I used is 8.50 for win32.


-- 
           Summary: Template behaviour when a template class has a member
                    template class deriving from its container
           Product: gcc
           Version: 4.3.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: pietro dot braione at polimi dot it
GCC target triplet: x86_64-unknown-linux-gnu


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


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

end of thread, other threads:[~2011-10-19  1:52 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-39777-4@http.gcc.gnu.org/bugzilla/>
2011-10-19  1:52 ` [Bug c++/39777] Template behaviour when a template class has a member template class deriving from its container paolo.carlini at oracle dot com
2009-04-15 15:18 [Bug c++/39777] New: " pietro dot braione at polimi dot it
2009-04-15 15:21 ` [Bug c++/39777] " pietro dot braione at polimi dot it
2009-04-15 15:40 ` pinskia at gcc dot gnu dot org
2009-04-15 17:04 ` paolo dot carlini at oracle dot com

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).