From: Bryan Duxbury Date: Fri, 19 Aug 2011 18:23:39 +0000 (+0000) Subject: THRIFT-1275. cpp: always prefix namespaces with ' ::' X-Git-Tag: 0.8.0~140 X-Git-Url: https://source.supwisdom.com/gerrit/gitweb?a=commitdiff_plain;h=0b7eeb59750fef5be018e6ec406da2da5be13c1b;p=common%2Fthrift.git THRIFT-1275. cpp: always prefix namespaces with ' ::' Ensures no accidental namespace clashes. Patch: Adam Simpkins git-svn-id: https://svn.apache.org/repos/asf/thrift/trunk@1159729 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/compiler/cpp/src/generate/t_cpp_generator.cc b/compiler/cpp/src/generate/t_cpp_generator.cc index 472644e7..2b5057d5 100755 --- a/compiler/cpp/src/generate/t_cpp_generator.cc +++ b/compiler/cpp/src/generate/t_cpp_generator.cc @@ -3737,10 +3737,17 @@ void t_cpp_generator::generate_serialize_list_element(ofstream& out, * @return Namespaces */ string t_cpp_generator::namespace_prefix(string ns) { + // Always start with "::", to avoid possible name collisions with + // other names in one of the current namespaces. + // + // We also need a leading space, in case the name is used inside of a + // template parameter. "MyTemplate<::foo::Bar>" is not valid C++, + // since "<:" is an alternative token for "[". + string result = " ::"; + if (ns.size() == 0) { - return ""; + return result; } - string result = ""; string::size_type loc; while ((loc = ns.find(".")) != string::npos) { result += ns.substr(0, loc);