laotao / protobuf

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

C++ headers use unqualified (=potentially ambiguous) names from std namespace #544

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
When used alongside a library that reuses (in a separate namespace) names from 
the standard library, protobuf headers may fail to compile with an "ambiguous 
symbol" error.

In my case, my project uses uBLAS, which defines the template 
boost::numeric::ublas::vector. Now I can't include the headers message.h, 
generated_message_reflection.h, unknown_field_set.h unmodified, because they 
refer to vector<...> rather than std::vector<...>, which creates an ambiguity 
in the context in which I'm including them.

A quick search through the code shows that this is a consistent pattern (at 
least with regards to the name "vector"), so I'm a little puzzled.

Original issue reported on code.google.com by moti...@gmail.com on 14 Aug 2013 at 8:59

GoogleCodeExporter commented 9 years ago
The code was originally written that way intentionally (following Google's code 
style). It's not encouraged anymore. Maybe we should do a cleanup to fix this 
issue (i.e., add "std::" prefix and remove the "using namespace std" from 
common.h).

Original comment by xiaof...@google.com on 14 Aug 2013 at 7:28

GoogleCodeExporter commented 9 years ago
There is also an issue with the 'max' function in 
google/protobuf/repeated_field.h. It seems to be a mistake as other std 
functions are prefixed in this file (copy, swap, ...).

I had an error when I tried to add protobuf to a project which also define its 
own generic max function outside any namespace.

Original comment by julien.d...@gmail.com on 17 Nov 2013 at 11:32

GoogleCodeExporter commented 9 years ago
I am having this issue now too since I am using irrlicht and it contains a 
string class.

c:\projects\crossingpoint\irrlicht\trunk\source\protobuf-2.5.0rc1\src\google\pro
tobuf\generated_message_util.h(71): error C2872: 'string' : ambiguous symbol
1>          could be 'c:\msdev2010\vc\include\xstring(2062) : 
std::basic_string<_Elem,_Traits,_Ax> std::string'
1>          with
1>          [
1>              _Elem=char,
1>              _Traits=std::char_traits<char>,
1>              _Ax=std::allocator<char>
1>          ]
1>          or       
'c:\projects\ultimatestrategy\irrlicht\include\irrstring.h(74) : 
irr::core::string'

Original comment by Richard....@gmail.com on 8 Dec 2013 at 2:15