1

I have a problem with the compiling of code with the xlC_r compiler on AIX OS. I have attached my code below which is causing the problem. I have tried to compile the code on MS Windows with microsoft compiler and also compiled it under Linux with gcc and everything worked fine. The compiler error which I get is following:

"...../ABC.h", line 12.22: 1540-0063 (S) The text "<" is unexpected.

I have searched the internet and I found some resources (link and link), I do not know how to integrate the solution into my code. One possible solution would be to remove the shared_ptr and just have the pointer value, but I do not like to manage the deleting of pointer by myself. I would relly appreciate any help.

ABC.h

#ifndef ABC_H
#define ABC_H

#include <vector>
#include <memory>

template<class SR_TYPE, class SM_TYPE>
class ABC {
   private:    
      std::shared_ptr<SR_TYPE> mpRV;
      std::vector<SM_TYPE>     mMsgs;

   public:
      ABC(void);
      ABC(SR_TYPE* pReturnValue);
      virtual ~ABC(void);
};    // ABC
template<class SR_TYPE, class SM_TYPE>
ABC<SR_TYPE, SM_TYPE>::ABC(void) {
}
template<class SR_TYPE, class SM_TYPE>
ABC<SR_TYPE, SM_TYPE>::ABC(SR_TYPE* pReturnValue) {
   mpRV.reset(pReturnValue);
}
template<class SR_TYPE, class SM_TYPE>
ABC<SR_TYPE, SM_TYPE>::~ABC(void) {
}
#endif // ABC_H

ABC.cpp

#include "ABC.h"

class ABCExtended : public ABC<int, std::string> {
   ABCExtended() :
      ABC<int, std::string>()
   {}
   ABCExtended(int* pReturnValue) :
      ABC<int, std::string>(pReturnValue)
   {}
};

Thanks in advance.

jww
  • 97,681
  • 90
  • 411
  • 885
joe_specimen
  • 295
  • 3
  • 19
  • **Do not add C tag for C++ questions!** – too honest for this site Aug 25 '15 at 17:11
  • 3
    And on which line in the code you show do you get the error? – Some programmer dude Aug 25 '15 at 17:12
  • Sorry for not being exact :( I am new to this :). The line in which the shared_ptr is. In the ABC.h file. – joe_specimen Aug 25 '15 at 17:16
  • 3
    You *do* build in C++11 (or higher) mode? Some compilers (like GCC and Clang) doesn't build in C++11 mode by default, you have to explicitly enable it. For example, for `g++`/`clang++` add the option `-std=c++11`. – Some programmer dude Aug 25 '15 at 17:18
  • @joe_specimen Sure that this Compiler supports the current standards? May be you missed some option like `-std=c++11`? – πάντα ῥεῖ Aug 25 '15 at 17:20
  • I know that for the Windows and Linux we are doing it in this way, but I do not know about AIX. I have to check with our build administrator if they use the switch for building this with c++11 standard. Does the xlc have a switch to turn the compiling to x++11 standard? – joe_specimen Aug 25 '15 at 17:23
  • @πάντα ῥεῖ Mhm, as I said I will have to contact our build admin to clarify this. – joe_specimen Aug 25 '15 at 17:31
  • @Joachim I have found that if I use #include "boost/smart_ptr/shared_ptr.hpp" then everything works. So, for now my solution will be to change all the std::shared_ptr with boost::shared_ptr. Obviously we are using xlC which is not C++11 compliant :(. – joe_specimen Aug 26 '15 at 08:43
  • @πάντα ῥεῖ I have found out that we are using xlC 11.1 which does not support fully C++11. So, this means that I will have to stick with `boost::shared_ptr`. – joe_specimen Aug 26 '15 at 11:22
  • Also see [IBM Technote 21051267](https://www-01.ibm.com/support/docview.wss?uid=swg21051267). – jww Nov 19 '18 at 00:35

2 Answers2

1

xlC is not C++11 conformant. Shared_ptr is not available there in std:: namespace. It does have special namespace for 'experimental' features, and shared_ptr might be there. Those expereimentals are in std::tr1, and you need to compile with __ IBMCPP_TR1__.

SergeyA
  • 61,605
  • 5
  • 78
  • 137
  • I have found following [link](https://www.ibm.com/developerworks/community/blogs/5894415f-be62-4bc0-81c5-3956e82276f3/entry/xlc_compiler_s_c_11_support50?lang=en) which states that the xlC supports c++11 standard since 2008. I also tried with boost::shared_ptr and I got the same problem. I will check tomorrow once again just to be sure that I did not miss something. What I wanted to know is, if the way in which I am implementing the class is only supported by c++11, or is there any other way to do this. – joe_specimen Aug 25 '15 at 19:39
  • It could be that also boost needs compiler support for c++11 standard. Currently we are using version 1.55 of boost. – joe_specimen Aug 25 '15 at 19:43
  • Well, the version of xlC I used to work with recently certainly did not have C++11 support in it. It might that it was outdated, of course. boost::shared_ptr is defintely available for C++03, so if you have similar issue, it means, you did not include appropriate boost header. – SergeyA Aug 25 '15 at 19:47
  • I have found that if I use `#include "boost/smart_ptr/shared_ptr.hpp"` then everything works. So, for now my solution will be to change all the `std::shared_ptr` with `boost::shared_ptr`. Obviously we are using xlC which is not C++11 compliant :(. – joe_specimen Aug 26 '15 at 08:41
  • I found out that we are using xlC version 11.1 which is not fully C++11 compliant :( – joe_specimen Aug 26 '15 at 11:22
0

shared_ptr is from the TR1 so it should be used from that namespace

change std::shared_ptr mpRV; to std::tr1::shared_ptr mpRV;

Compile with -D__IBMCPP_TR1__

  • Yes, this would probably work (already suggested by SergeyA), but I am working in corporate environment, so I do not have the rights to change how the programs are built :( and I already changed the `std::shared_ptr` to `boost::shared_ptr`. Anyway thanks for the suggestion, but I will make this as a solution to my problem. – joe_specimen Aug 26 '15 at 13:17