c++ - g++ compilation error on AIX unix server -


i have socket program server code written in c++.

i'm facing below error when compiled using g++ compiler(os : unix aix). same code compiled using cc compiler(os : unix sun os ). please let me know how resolve it.

  • code snippet

    enum sockstates          {                  inopen  = ios::in,                  outopen = ios::out,                  open    = ios::in | ios::out,          }; 
  • error

    g++ -gxcoff -maix64 -shared -fpic -fpermissive -w -libstd=c++11ox -i/devt/flex/java/include -i/devt/flex/java/include/aix -i/tmp/ribscomp/server/include -c -o server.o server.cc   ssocket.h:721:26: error: calls overloaded operators cannot appear in constant-expression     open = ios::in | ios::out,                          ^  
  • g++ version

    g++ -v 

using built-in specs.

collect_gcc=g++  collect_lto_wrapper=/opt/freeware/libexec/gcc/powerpc-ibm-aix7.1.0.0/4.8.2/lto-wrapper  target: powerpc-ibm-aix7.1.0.0  configured with: ../gcc-4.8.2/configure --with-as=/usr/bin/as --with-ld=/usr/bin/ld --enable-languages=c,c++,fortran --prefix=/opt/freeware --mandir=/opt/freeware/man --infodir=/opt/freeware/info --enable-version-specific-runtime-libs --disable-nls --enable-decimal-float=dpd --host=powerpc-ibm-aix7.1.0.0  thread model: aix  gcc version 4.8.2 (gcc) 

the problem gcc's standard library defines std::ios::openmode enumeration type overloaded operators, , in c++03 operators not allowed appear in constant expression (such initializer enumerator).

it works solaris compiler because (i assume) openmode integral type. standard allows either, both compilers conforming.

in c++11 mode operators constexpr , can used here, 1 solution compile -std=c++11 or -std=gnu++11, aware abi c++11 types not finalised in gcc 4.8.

another solution replace enumerators constant variables:

enum sockstates { _max = std::numeric_limits<int>::max() };  const sockstates inopen  = ios::in; const sockstates outopen = ios::out; const sockstates open    = ios::in | ios::out; 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -