0 Replies Latest reply on Aug 12, 2011 8:23 AM by ally

    C++ template error: icpc complains, g++ does not ... who is right?

    ally

      Hi

       

      I'm trying to compile a C++ application to run on the SCC cores (actually it's an MPI application, but that doesn't matter for this post).

       

      I got a load of template-related errors with icpc, but these errors do not occur with g++.

       

      Here is a simple test case derived from my application:

       

      template <class T >
      class container
      {
      public:
        container();
        ~container();
        T get_element();
      };

       


      class abstract_class
      {
      public:
      abstract_class();
      virtual void pure_virtual() = 0;
      };

       

      class my_container: public container<abstract_class>
      {
      public:
        my_container();
        ~my_container();
      };

       

      Doing:

       

      g++ -c minex.cc

       

      works - i.e., there are no errors.

       

      Doing:

       

      icpc -c minex.cc

       

      gives this error:

       

      minex.cc(8): error: function returning abstract class "abstract_class" is not allowed:
                  function "abstract_class::pure_virtual" is a pure virtual function
          T get_element();
            ^
                detected during instantiation of class "container<T> [with T=abstract_class]" at line 19

       

      compilation aborted for minex.cc (code 2)

       

      It seems like the problem is that by instantiating "container" with "abstract_class" as the template parameter "T", we require that the "get_element" method of the instantiated class returns an instance of type "abstract_class".  However, because "abstract_class" contains a pure virtual method, such an instance can never be created.

       

      So it seems that perhaps icpc is right to give an error here.

       

      However, this sort of code is embedded in the large application I am working on, and g++ compiles the application and it runs successfully.

       

      Can anyone comment on whether this behaviour from icpc is expected?

       

      Also, is there some way to tell icpc to be less strict and let this example go through?

       

      Thanks

       

      Ally