summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNat Goodspeed <nat@lindenlab.com>2021-11-02 11:31:47 -0400
committerNat Goodspeed <nat@lindenlab.com>2021-11-02 11:31:47 -0400
commit95958bc8b2a5340bef93996f2ff0c04956bfb743 (patch)
tree1a953ea3dfe02d9b541ff55c0323473344f476aa
parent10692ab4a4f999e1ee302675e4ffb84f37a52643 (diff)
SL-16207: Guess Microsoft compiler isn't smart about default params?
clang allows us to specify, as a default function parameter, an expression involving a preceding parameter, e.g. (char* ptr, size_t len=strlen(ptr)). The Microsoft compiler produces errors, requiring more overloads to address that. Also #undef llstring.h's declaration helper macros at the bottom of the file. Once we've used them to declare stuff, they need not (should not) be visible to the consuming source file.
-rw-r--r--indra/llcommon/llstring.h26
1 files changed, 24 insertions, 2 deletions
diff --git a/indra/llcommon/llstring.h b/indra/llcommon/llstring.h
index a0598e8a11..54e3f9ee63 100644
--- a/indra/llcommon/llstring.h
+++ b/indra/llcommon/llstring.h
@@ -749,17 +749,29 @@ LL_COMMON_API unsigned int ll_wstring_default_code_page();
// This is like ll_convert_forms(), with the added complexity of a code page
// parameter that may or may not be passed.
#define ll_convert_cp_forms(aliasmacro, OUTSTR, INSTR, longname) \
+/* declare the only nontrivial implementation (in .cpp file) */ \
LL_COMMON_API OUTSTR longname( \
const INSTR::value_type* in, \
- size_t len=ll_convert_length(in), \
+ size_t len, \
unsigned int code_page=ll_wstring_default_code_page()); \
+/* if passed only a char pointer, scan for nul terminator */ \
+inline auto longname(const INSTR::value_type* in) \
+{ \
+ return longname(in, ll_convert_length(in)); \
+} \
+/* if passed string and length, extract its char pointer */ \
inline auto longname( \
const INSTR& in, \
- size_t len=in.length(), \
+ size_t len, \
unsigned int code_page=ll_wstring_default_code_page()) \
{ \
return longname(in.c_str(), len, code_page); \
} \
+/* if passed only a string object, no scan, pass known length */ \
+inline auto longname(const INSTR& in) \
+{ \
+ return longname(in.c_str(), in.length()); \
+} \
aliasmacro(OUTSTR, INSTR, longname(in)); \
aliasmacro(OUTSTR, const INSTR::value_type*, longname(in))
@@ -1967,4 +1979,14 @@ void LLStringUtilBase<T>::truncate(string_type& string, size_type count)
string.resize(count < cur_size ? count : cur_size);
}
+// The good thing about *declaration* macros, vs. usage macros, is that now
+// we're done with them: we don't need them to bleed into the consuming source
+// file.
+#undef ll_convert_alias
+#undef ll_convert_u16_alias
+#undef ll_convert_wstr_alias
+#undef LL_CONVERT_COPY_CHARS
+#undef ll_convert_forms
+#undef ll_convert_cp_forms
+
#endif // LL_STRING_H