c++/8273: g++ can not generate an instance of a template containg a template instance

bill@graysoft.com bill@graysoft.com
Thu Oct 17 17:16:00 GMT 2002


>Number:         8273
>Category:       c++
>Synopsis:       g++ can not generate an instance of a template containg a template instance
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          rejects-legal
>Submitter-Id:   net
>Arrival-Date:   Thu Oct 17 17:16:01 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     W. Beckett
>Release:        gcc-3.1.1
>Organization:
>Environment:
Red Hat Linux 7.3. binutil-2.13 and gcc-3.1.1 were pulled
from the GNU site and configured with all default options
>Description:
Given two structure templates M and X, an attempt to
include an instance of M parameterized by a member
function of X in X results in a syntax error when
X is instantiated. More detail is given in annotations
in the following short program.
>How-To-Repeat:
g++ -static the above program
>Fix:
The technique does not seem to be usable -- the fix is
to try something else.
>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: text/plain; name="t4.cpp"
Content-Disposition: inline; filename="t4.cpp"


/* The following template is intended to take a structure   */
/* and a pointer to a member function of that structure     */
/* as template parameters.                                  */

template <class T, int (T::*f)()> struct M {};

/* The following template defines a set of structures       */
/* all of which include a member function int p(). The      */
/* idea is for this member function to be used as an actual */
/* template parameter when generating an instance of M.     */

template <class A>
struct X
{
      A a;

      int p() {}

      M<X,X::p> m;
};

/* However, an attempt to instantiate an instance of X      */
/* will not compile.                                        */

main() 
{
      X<int> x;
}

/* Note that this program produces the following error      */
/* messages --                                              */

/* t4.cpp: In instantiation of `X<int>':                    */
/* t4.cpp:28:   instantiated from here                      */
/* t4.cpp:20: `p' is not a member of type `X<int>'          */

/* Note also that this program does compile using the       */
/* Sun Microsystems compiler, Forte Developer 7 C++         */
/* 5.4 2002/03/09 running on a Sparc Ultra 30 under Solaris */
/* 8 and also using the HP (formerly Compaq) compiler,      */
/* Compaq C++ V6.3-008 for Tru64 UNIX V5.1A (Rev. 1885)     */
/* running on an alpha.                                     */

/* The Microsoft compiler included with Visual Studio,      */
/* version 6, however, also does not compile the example    */
/* but produces instead the following error messages --     */
  
/* $ cl -c -nologo -MD -W3 -GX -O2 -I 'F:\development\DevStudio\VC\include' \                */
/*         -D WIN32 -D NDEBUG -D _WINDOWS -D _AFXDLL -D _MBCS t4.cpp                         */
/* t4.cpp                                                                                    */
/* t4.cpp(20) : error C2955: 'X' : use of class template requires template argument list     */
/* t4.cpp(20) : error C2955: 'X' : use of class template requires template argument list     */
/* t4.cpp(20) : error C2027: use of undefined type 'X<int>'                                  */
/* t4.cpp(20) : error C2327: 'X<int>::p' : member from enclosing class is not a type name,   */
/*              static, or enumerator                                                        */
/* t4.cpp(20) : error C2065: 'p' : undeclared identifier                                     */
/* t4.cpp(20) : error C2955: 'M' : use of class template requires template argument list     */
/* t4.cpp(20) : warning C4200: nonstandard extension used : zero-sized array in struct/union */
/* t4.cpp(20) : fatal error C1903: unable to recover from previous error(s); stopping        */
/*              compilation                                                                  */



More information about the Gcc-bugs mailing list