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; 5+ 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] 5+ messages in thread

* [Bug c++/39777] Template behaviour when a template class has a member template class deriving from its container
  2009-04-15 15:18 [Bug c++/39777] New: Template behaviour when a template class has a member template class deriving from its container pietro dot braione at polimi dot it
@ 2009-04-15 15:21 ` 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
  2 siblings, 0 replies; 5+ messages in thread
From: pietro dot braione at polimi dot it @ 2009-04-15 15:21 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from pietro dot braione at polimi dot it  2009-04-15 15:20 -------
Created an attachment (id=17643)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=17643&action=view)
the example program


-- 


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


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

* [Bug c++/39777] Template behaviour when a template class has a member template class deriving from its container
  2009-04-15 15:18 [Bug c++/39777] New: Template behaviour when a template class has a member template class deriving from its container 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
  2 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2009-04-15 15:40 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from pinskia at gcc dot gnu dot org  2009-04-15 15:39 -------
The issue comes down to how is Inc injected into Inc.  I can't remember the
exact rules but I think GCC's behavior is correct.


-- 


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


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

* [Bug c++/39777] Template behaviour when a template class has a member template class deriving from its container
  2009-04-15 15:18 [Bug c++/39777] New: Template behaviour when a template class has a member template class deriving from its container 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
  2 siblings, 0 replies; 5+ messages in thread
From: paolo dot carlini at oracle dot com @ 2009-04-15 17:04 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from paolo dot carlini at oracle dot com  2009-04-15 17:04 -------
For the record, the Intel compiler - which I trust much more than DM, sorry -
behaves the same as GCC. I strongly believe GCC is correct. I even think we
have something closed about this issue, let me see if I find it...


-- 


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


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

* [Bug c++/39777] Template behaviour when a template class has a member template class deriving from its container
       [not found] <bug-39777-4@http.gcc.gnu.org/bugzilla/>
@ 2011-10-19  1:52 ` paolo.carlini at oracle dot com
  0 siblings, 0 replies; 5+ messages in thread
From: paolo.carlini at oracle dot com @ 2011-10-19  1:52 UTC (permalink / raw)
  To: gcc-bugs

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

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
                 CC|gcc-bugs at gcc dot gnu.org |
         Resolution|                            |INVALID

--- Comment #4 from Paolo Carlini <paolo.carlini at oracle dot com> 2011-10-19 01:51:38 UTC ---
This is even rejected now.


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

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

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-04-15 15:18 [Bug c++/39777] New: Template behaviour when a template class has a member template class deriving from its container 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
     [not found] <bug-39777-4@http.gcc.gnu.org/bugzilla/>
2011-10-19  1:52 ` paolo.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).