laotao / protobuf

Automatically exported from code.google.com/p/protobuf
Other
0 stars 0 forks source link

by_symbol_.insert(iter, make_pair(name, value)); fails with Sun Studio 12 #166

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Try to build with Sun Studio 12
2.
3.

What is the expected output? What do you see instead?
Line 131 of google/protobuf/descriptor_database.cc should successfully 
expand.

What version of the product are you using? On what operating system?
2.3.0, Sun Studio 12, Solaris 9 and 10.

Please provide any additional information below.

The error is:

by_symbol_.insert(iter, make_pair(name, value)); fails with:

gmake[4]: Entering directory 
`/home/maciej/src/opencsw/pkg/protobuf/trunk/work/solaris9-sparc/build-isa-
sparcv8/protobuf-2.3.0/src'
source='google/protobuf/descriptor_database.cc' 
object='descriptor_database.lo' libtool=yes \
        DEPDIR=.deps depmode=none /bin/bash ../depcomp \
        /bin/bash ../libtool --tag=CXX   --mode=compile 
/opt/studio/SOS12/SUNWspro/bin/CC -DHAVE_CONFIG_H -I. -I..   -
I/opt/csw/include -D_REENTRANT   -xmemalign=8s -xO3 -m32 -xarch=v8 -c -o 
descriptor_database.lo `test -f 'google/protobuf/descriptor_database.cc' || 
echo './'`google/protobuf/descriptor_database.cc
libtool: compile:  /opt/studio/SOS12/SUNWspro/bin/CC -DHAVE_CONFIG_H -I. -
I.. -I/opt/csw/include -D_REENTRANT -xmemalign=8s -xO3 -m32 -xarch=v8 -c 
google/protobuf/descriptor_database.cc  -KPIC -DPIC -o 
.libs/descriptor_database.o
"./google/protobuf/descriptor.h", line 324: Warning: Identifier expected 
instead of "}".
"./google/protobuf/descriptor.h", line 343: Warning: Identifier expected 
instead of "}".
"./google/protobuf/descriptor.h", line 354: Warning: Identifier expected 
instead of "}".
"./google/protobuf/wire_format_lite.h", line 95: Warning: Identifier 
expected instead of "}".
"./google/protobuf/wire_format_lite.h", line 118: Warning: Identifier 
expected instead of "}".
"./google/protobuf/wire_format_lite.h", line 133: Warning: Identifier 
expected instead of "}".
"google/protobuf/descriptor_database.cc", line 131: Error: Could not find a 
match for std::map<std::string,const 
google::protobuf::FileDescriptorProto*>::insert(__rwstd::__rb_tree<std::str
ing, std::pair<const std::string, const 
google::protobuf::FileDescriptorProto*>, 
__rwstd::__select1st<std::pair<const std::string, const 
google::protobuf::FileDescriptorProto*>, std::string>, 
std::less<std::string>, std::allocator<std::pair<const std::string, const 
google::protobuf::FileDescriptorProto*>>>::iterator, std::pair<std::string, 
const google::protobuf::FileDescriptorProto*>) needed in 
google::protobuf::SimpleDescriptorDatabase::DescriptorIndex<const 
google::protobuf::FileDescriptorProto*>::AddSymbol(const std::string &, 
const google::protobuf::FileDescriptorProto*).
"google/protobuf/descriptor_database.cc", line 69:     Where: While 
instantiating 
"google::protobuf::SimpleDescriptorDatabase::DescriptorIndex<const 
google::protobuf::FileDescriptorProto*>::AddSymbol(const std::string &, 
const google::protobuf::FileDescriptorProto*)".
"google/protobuf/descriptor_database.cc", line 69:     Where: Instantiated 
from google::protobuf::SimpleDescriptorDatabase::DescriptorIndex<const 
google::protobuf::FileDescriptorProto*>::AddFile(const 
google::protobuf::FileDescriptorProto&, const 
google::protobuf::FileDescriptorProto*).
"google/protobuf/descriptor_database.cc", line 265:     Where: Instantiated 
from non-template code.
1 Error(s) and 6 Warning(s) detected.
gmake[4]: *** [descriptor_database.lo] Error 1
gmake[4]: Leaving directory 
`/home/maciej/src/opencsw/pkg/protobuf/trunk/work/solaris9-sparc/build-isa-
sparcv8/protobuf-2.3.0/src'

I looked up the prototype of the insert() method for Sun Studio:

/opt/studio/SOS12/SUNWspro/prod/include/CC/stlport4/stl/_map.h

line 171:

  iterator insert(iterator position, const value_type& __x)
    { return _M_t.insert_unique(position, __x); }

Looks right to me, since by_symbol_ is of type:
map<string, Value> by_symbol_;

I'm not sure what is the problem there.  The iterator (here "iter") has the 
right type:

typename std :: map < string , Value > :: iterator iter = 
FindLastLessOrEqual ( name ) ;

I'm suspecting something about the 'name' variable.  The error message says 
that it can't find a match for:
AddSymbol(const std::string &, const 
google::protobuf::FileDescriptorProto*)

But higher up, the map definition is <string, Value>, so I suspect that 
there might be something about "string" vs "const string&".

Original issue reported on code.google.com by maciej.b...@gmail.com on 21 Feb 2010 at 8:50

GoogleCodeExporter commented 9 years ago
If you change "make_pair(name, value)" to "make_pair<std::string,const 
FileDescriptorProto*>(name, value)", does it work?  If so, your compiler's 
definition 
of the "pair" template is apparently missing a constructor.

Original comment by kenton@google.com on 22 Feb 2010 at 11:20

GoogleCodeExporter commented 9 years ago
I worked around the issue by using an alternative STL implementation.

This page has something that might be a different workaround.
http://developers.sun.com/solaris/articles/cmp_stlport_libCstd.html

This issue might be a duplicate of issue 134.

Original comment by maciej.b...@gmail.com on 28 Feb 2010 at 12:18

GoogleCodeExporter commented 9 years ago
Changing
  by_symbol_.insert(iter, make_pair(name, value));
to
  by_symbol_.insert(iter, map<string, Value>::value_type(name, value));
resolves the problem on Sun compiler when using Cstd lib (i.e. without 
stlport4).

The problem appears to be that make_pair returns pair<string, Value> but the 
insert operation requires pair<const string, Value> (i.e. value_type) and the 
pair conversion is not supported in the default stl implementation provided 
with this compiler.

Original comment by philip.l...@gmail.com on 24 Aug 2010 at 10:18

GoogleCodeExporter commented 9 years ago
BTW, compiler/command_line_interface.cc contains a similar problem with Sun 
Studio compiler with default STL implementation:
Changing
      proto_path_.push_back(make_pair("", "."));
to
      proto_path_.push_back(make_pair<string, string>("", "."));
resolves problem (or replace make_pair with value_type for collection).

Original comment by philip.l...@gmail.com on 24 Aug 2010 at 10:31

GoogleCodeExporter commented 9 years ago
Great, a solution.  Will fix for next release.

Original comment by kenton@google.com on 24 Aug 2010 at 10:10

GoogleCodeExporter commented 9 years ago
Fixed in r353

Original comment by liujisi@google.com on 3 Dec 2010 at 9:15

GoogleCodeExporter commented 9 years ago
make_pair<string, string> is not compatible with C++0x.  You probably want 
pair<string, string> as a workaround for broken stdlibs.

Original comment by james.de...@gmail.com on 26 Apr 2011 at 7:34