public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/45698]  New: C++0x Variadic Templates: Infinite template recursion rather than an error message
@ 2010-09-17  0:44 Clint dot Smullen at gmail dot com
  2010-09-17  1:25 ` [Bug c++/45698] " redi at gcc dot gnu dot org
  0 siblings, 1 reply; 5+ messages in thread
From: Clint dot Smullen at gmail dot com @ 2010-09-17  0:44 UTC (permalink / raw)
  To: gcc-bugs

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 3245 bytes --]

The first case works without any errors:

#include <tuple>

template<typename Type>
class A { 
};


template<typename... Types>
class B : A<B<Types...> > { 
   std::tuple<Types...> t;
};

Now, altering the tuple to hold a struct derived from Types also works:

template<typename T>
struct C_M { };

template<typename... Types>
class C : A<C<Types...> > { 
   std::tuple<C_M<Types>...> t;
};

However, declaring the struct inside, like this:

template<typename... Types>
class D : A<D<Types...> > { 
   template<typename T>
   struct M { };

   std::tuple<M<Types>...> t;
};

Does not, as GCC 4.4.3 gives this error:

cxxtest.cpp:24: error: template instantiation depth exceeds maximum of 500 (use
-ftemplate-depth-NN to increase the maximum) instantiating ‘class A<D<int,
char, bool> >’
cxxtest.cpp:24:   instantiated from ‘D<int, char, bool>’
cxxtest.cpp:28:   instantiated from ‘D<int, char, bool>’
cxxtest.cpp:28:   instantiated from ‘D<int, char, bool>’
cxxtest.cpp:28:   instantiated from ‘D<int, char, bool>’
(repeats another 496 times)

As shown, the error does have something to do with the tuple declaration on
recursive instantiation of class D in the declaration. This error comes out of
nowhere, as D is not even mentioned by the tuple declaration.

What is pretty much impossible to determine from this error (but is implied by
the correct operation of C above) is that the tuple declaration is missing a
typename:

template<typename... Types>
class E : A<E<Types...> > {
   template<typename T>
   struct M { };

   std::tuple<typename M<Types>...> t;
};

I've no idea how GCC is arriving at the infinite recursion, but improved
analysis that could allow GCC to determine the actual error (or a near
approximation thereof, as for other missing typename errors) would be very
nice. Here is the complete test code with the erroneous line commented out:

#include <tuple>

template<typename Type>
class A {
};


template<typename... Types>
class B : A<B<Types...> > {
   std::tuple<Types...> t;
};


template<typename T>
struct C_M { };

template<typename... Types>
class C : A<C<Types...> > {
   std::tuple<C_M<Types>...> t;
};


template<typename... Types>
class D : A<D<Types...> > {
   template<typename T>
   struct M { };

// std::tuple<M<Types>...> t;
};


template<typename... Types>
class E : A<E<Types...> > {
   template<typename T>
   struct M { };

   std::tuple<typename M<Types>...> t;
};

int main() {
   B<int, char, bool> b;
   C<int, char, bool> c;
   D<int, char, bool> d;
   E<int, char, bool> e;
   return 0;
}

This compiles cleanly, except for unused variables warnings. I do not have a
GCC 4.5 or newer installation to compare against.


-- 
           Summary: C++0x Variadic Templates: Infinite template recursion
                    rather than an error message
           Product: gcc
           Version: 4.4.3
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: Clint dot Smullen at gmail dot com
 GCC build triplet: x86_64-linux-gnu
  GCC host triplet: x86_64-linux-gnu
GCC target triplet: x86_64-linux-gnu


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


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

* [Bug c++/45698] C++0x Variadic Templates: Infinite template recursion rather than an error message
  2010-09-17  0:44 [Bug c++/45698] New: C++0x Variadic Templates: Infinite template recursion rather than an error message Clint dot Smullen at gmail dot com
@ 2010-09-17  1:25 ` redi at gcc dot gnu dot org
  0 siblings, 0 replies; 5+ messages in thread
From: redi at gcc dot gnu dot org @ 2010-09-17  1:25 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from redi at gcc dot gnu dot org  2010-09-17 01:25 -------
The 'typename' should not be necessary, and 4.5 and 4.6 compile it without
problems


-- 


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


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

* [Bug c++/45698] C++0x Variadic Templates: Infinite template recursion rather than an error message
       [not found] <bug-45698-4@http.gcc.gnu.org/bugzilla/>
  2011-05-25 18:00 ` jason at gcc dot gnu.org
  2011-05-25 19:54 ` jason at gcc dot gnu.org
@ 2011-05-25 20:32 ` jason at gcc dot gnu.org
  2 siblings, 0 replies; 5+ messages in thread
From: jason at gcc dot gnu.org @ 2011-05-25 20:32 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Jason Merrill <jason at gcc dot gnu.org> 2011-05-25 20:30:19 UTC ---
Author: jason
Date: Wed May 25 20:30:12 2011
New Revision: 174236

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=174236
Log:
    PR c++/45698
    * pt.c (dependent_template_arg_p): See through ARGUMENT_PACK_SELECT.

Added:
    branches/gcc-4_6-branch/gcc/testsuite/g++.dg/cpp0x/variadic110.C
Modified:
    branches/gcc-4_6-branch/gcc/cp/ChangeLog
    branches/gcc-4_6-branch/gcc/cp/pt.c
    branches/gcc-4_6-branch/gcc/testsuite/ChangeLog


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

* [Bug c++/45698] C++0x Variadic Templates: Infinite template recursion rather than an error message
       [not found] <bug-45698-4@http.gcc.gnu.org/bugzilla/>
  2011-05-25 18:00 ` jason at gcc dot gnu.org
@ 2011-05-25 19:54 ` jason at gcc dot gnu.org
  2011-05-25 20:32 ` jason at gcc dot gnu.org
  2 siblings, 0 replies; 5+ messages in thread
From: jason at gcc dot gnu.org @ 2011-05-25 19:54 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Jason Merrill <jason at gcc dot gnu.org> 2011-05-25 19:52:14 UTC ---
Author: jason
Date: Wed May 25 19:52:10 2011
New Revision: 174229

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=174229
Log:
    PR c++/45698
    * pt.c (dependent_template_arg_p): See through ARGUMENT_PACK_SELECT.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/variadic110.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/pt.c
    trunk/gcc/testsuite/ChangeLog


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

* [Bug c++/45698] C++0x Variadic Templates: Infinite template recursion rather than an error message
       [not found] <bug-45698-4@http.gcc.gnu.org/bugzilla/>
@ 2011-05-25 18:00 ` jason at gcc dot gnu.org
  2011-05-25 19:54 ` jason at gcc dot gnu.org
  2011-05-25 20:32 ` jason at gcc dot gnu.org
  2 siblings, 0 replies; 5+ messages in thread
From: jason at gcc dot gnu.org @ 2011-05-25 18:00 UTC (permalink / raw)
  To: gcc-bugs

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

Jason Merrill <jason at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
                 CC|                            |jason at gcc dot gnu.org
         Resolution|                            |FIXED
   Target Milestone|---                         |4.5.0

--- Comment #2 from Jason Merrill <jason at gcc dot gnu.org> 2011-05-25 17:16:16 UTC ---
Fixed in 4.5.0.


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

end of thread, other threads:[~2011-05-25 20:32 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-09-17  0:44 [Bug c++/45698] New: C++0x Variadic Templates: Infinite template recursion rather than an error message Clint dot Smullen at gmail dot com
2010-09-17  1:25 ` [Bug c++/45698] " redi at gcc dot gnu dot org
     [not found] <bug-45698-4@http.gcc.gnu.org/bugzilla/>
2011-05-25 18:00 ` jason at gcc dot gnu.org
2011-05-25 19:54 ` jason at gcc dot gnu.org
2011-05-25 20:32 ` jason at gcc dot gnu.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).