2 Replies Latest reply: Aug 19, 2013 10:43 AM by simonmcqueen RSS

    Suspected Solaris Studio C++ Compile bug - compiling template class with function definition outside class declaration

    simonmcqueen

      Hi there,

       

      I think I've found a bug in SunCC. It manifests compiling a template class member function with its definition outside of the class declaration when the class is a template with two parameters if, and only if, one is a template class. The code in the below example all compiles fine with GCC and Visual Studio.

       

      Here's the code:

       

      template <typename R, class T>
      class Foo
      {
         template<typename U> void fun(const U&);
      };
      
      /* Compiles OK */
      template <typename R, class T>
      template <typename U>
      void
      Foo<R, T>::fun(const U&) {}
      
      template <template <typename S> class T>
      class Bar
      {
         template<typename U> void fun(const U&);
      };
      
      /* Compiles OK */
      template <template <typename S> class T>
      template <typename U>
      void
      Bar<T>::fun(const U&) {}
      
      /* Compiles OK */
      template <typename R, template <typename S> class T>
      class Baz
      {
         template<typename U> void fun(const U&)
         {
             /* definition in-line within declaration */
         }
      };
      
      /* Qux == Baz except fun defintion is outside of class declaration */
      template <typename R, template <typename S> class T>
      class Qux
      {
         template<typename U> void fun(const U&);
      };
      
      /* Fails to compile */
      template <typename R, template <typename S> class T>
      template <typename U>
      void
      Qux<R, T>::fun(const U&) {} // line #46
      
      int main (int, char*[]) { return 0; }
      

       

      The error output and platform details look like this:

      -bash-3.2$ CC test.cpp 
      "test.cpp", line 46: Error: Could not find a match for Qux<R, T<S>>::fun<Qux<R, T<S>>::U>(const U&).
      "test.cpp", line 46: Error: Too few args in template, from T<S> on ignored.
      2 Error(s) detected.
      -bash-3.2$ uname -a
      SunOS ultra4 5.10 Generic_147147-26 sun4u sparc SUNW,Sun-Fire-V440
      -bash-3.2$ CC -V
      CC: Sun C++ 5.12 SunOS_sparc 2011/11/16
      -bash-3.2$ pkginfo -l SPRO-12-3-c++
         PKGINST:  SPRO-12-3-c++
            NAME:  C++ Compilers
        CATEGORY:  application
            ARCH:  sparc
         VERSION:  12.3,REV=1
         BASEDIR:  /opt
          VENDOR:  Oracle Corporation
            DESC:  C++ Compilers
          PSTAMP:  buba20111116070658
        INSTDATE:  Aug 07 2013 10:57
         HOTLINE:  Please contact your local service provider
          STATUS:  completely installed
           FILES:     1578 installed pathnames
                        45 shared pathnames
                        73 directories
                        10 executables
                    514060 blocks used (approx)
      
      -bash-3.2$
      

      Does anyone know if this is a known issue please? If it isn't, can anyone please tell me where the issue tracker is for Sun Studio so I can report this?

       

      Thanks & regards,

      Simon.

       

      Message was edited by: simonmcqueen

       

      Message was edited by: simonmcqueen