Bug 56449 - operator-> in a template class can lead to infinite template instantiation
Summary: operator-> in a template class can lead to infinite template instantiation
Status: RESOLVED DUPLICATE of bug 49118
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.6.3
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-02-25 22:38 UTC by Vasily Sukhanov
Modified: 2013-02-25 22:45 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Vasily Sukhanov 2013-02-25 22:38:36 UTC
Code example:

template<class T> struct Loop { Loop<T*> operator->(); };
Loop<int> i, j = i->something;

The compiler doesn't diagnose infinite Loop<> instantiation. Even CLI option ftemplate-depth=n doesn't help.
Comment 1 Jonathan Wakely 2013-02-25 22:42:12 UTC
Both 4.7 and 4.8 exit with a sensible diagnostic:

a.cc:2:19: error: template instantiation depth exceeds maximum of 900 (use -ftemplate-depth= to increase the maximum) instantiating ‘Loop<T*> Loop<T>::operator->() [with T = int************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************]’
a.cc:2:19:   recursively required from ‘Loop<T*> Loop<T>::operator->() [with T = int]’
a.cc:2:19:   required from here

a.cc:2:19: error: template instantiation depth exceeds maximum of 900 (use -ftemplate-depth= to increase the maximum) instantiating ‘struct Loop<int*************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************>’
a.cc:2:19:   recursively required from ‘Loop<T*> Loop<T>::operator->() [with T = int]’
a.cc:2:19:   required from here

a.cc:2:19: error: invalid use of incomplete type ‘struct Loop<int*************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************>’
a.cc:1:26: error: declaration of ‘struct Loop<int*************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************>’
Comment 2 Jakub Jelinek 2013-02-25 22:45:10 UTC
Dup of PR49118.

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