Re: Remove templatization from bformat() ?

2016-11-26 Thread Guillaume Munch

Le 24/11/2016 à 00:33, Tommaso Cucinotta a écrit :

Hi,

while playing with strings, I've just run into a mysterious linking
error [1] which, after a bit of digging, turned out to be decrypted as
[2]. Basically, [2] is obtained by removing all templatization code for
bformat() in lstrings.h. All template implementations are completely
specialized on specific types, and do NOT make any actual use of the
template machinery (indeed, LyX compiles and links :-) ). Leaving aside
the specific error of the code snippet, as [2] is way more readable than
[1], I'd be totally in favor of pushing such a patch, which I'm
attaching. Any thoughts?


Hi Tommaso,

Looks good. Either that, or somebody with enough motivation implements
bformat in full generality which seems to have been the original
intention (see e.g. 6a55be95). This would have been another solution to 
your linking issue.




Remove templatization from bformat() ?

2016-11-23 Thread Tommaso Cucinotta

Hi,

while playing with strings, I've just run into a mysterious linking error [1] 
which, after a bit of digging, turned out to be decrypted as [2]. Basically, 
[2] is obtained by removing all templatization code for bformat() in 
lstrings.h. All template implementations are completely specialized on specific 
types, and do NOT make any actual use of the template machinery (indeed, LyX 
compiles and links :-) ). Leaving aside the specific error of the code snippet, 
as [2] is way more readable than [1], I'd be totally in favor of pushing such a 
patch, which I'm attaching. Any thoughts?

Thanks,

T.

  CXXLDlyx
liblyxcore.a(Converter.o): In function `lyx::Converters::checkAuth(lyx::Converter const&, 
std::__cxx11::basic_string 
const&)':
/home/tommaso/lyx-trunk-ws/lyx/src/Converter.cpp:289: undefined reference to `std::__cxx11::basic_string 
lyx::support::bformat, std::__cxx11::basic_string, 
std::__cxx11::basic_string >(std::__cxx11::basic_string const&, 
std::__cxx11::basic_string, std::__cxx11::basic_string, std::__cxx11::basic_string)'
collect2: error: ld returned 1 exit status
Makefile:2170: recipe for target 'lyx' failed

[2]

Converter.cpp: In member function ‘bool lyx::Converters::checkAuth(const 
lyx::Converter&, const string&)’:
Converter.cpp:289:115: error: no matching function for call to ‘bformat(const 
docstring, const string, const string, const string)’
   "files, if instructed to do so by a maliciously crafted .lyx document."), 
conv.command(), conv.from(), conv.to());

   ^
In file included from Converter.cpp:35:0:
support/lstrings.h:348:11: note: candidate: lyx::docstring 
lyx::support::bformat(const docstring&, int)
 docstring bformat(docstring const & fmt, int arg1);
   ^~~
support/lstrings.h:348:11: note: candidate: lyx::docstring 
lyx::support::bformat(const docstring&, int)
...
>From a7307afb7f12c2117dea72a639417a57a8cb8df3 Mon Sep 17 00:00:00 2001
From: Tommaso Cucinotta 
Date: Thu, 24 Nov 2016 00:30:13 +0100
Subject: [PATCH] Remove unneeded templatization code from bformat().

---
 src/support/lstrings.cpp | 24 ++--
 src/support/lstrings.h   | 37 -
 2 files changed, 18 insertions(+), 43 deletions(-)

diff --git a/src/support/lstrings.cpp b/src/support/lstrings.cpp
index 9eb9e43d..0dd8075e 100644
--- a/src/support/lstrings.cpp
+++ b/src/support/lstrings.cpp
@@ -1408,7 +1408,6 @@ std::string formatFPNumber(double x)
 }
 
 
-template<>
 docstring bformat(docstring const & fmt, int arg1)
 {
 	LATTEST(contains(fmt, from_ascii("%1$d")));
@@ -1417,7 +1416,6 @@ docstring bformat(docstring const & fmt, int arg1)
 }
 
 
-template<>
 docstring bformat(docstring const & fmt, long arg1)
 {
 	LATTEST(contains(fmt, from_ascii("%1$d")));
@@ -1427,7 +1425,6 @@ docstring bformat(docstring const & fmt, long arg1)
 
 
 #ifdef LYX_USE_LONG_LONG
-template<>
 docstring bformat(docstring const & fmt, long long arg1)
 {
 	LATTEST(contains(fmt, from_ascii("%1$d")));
@@ -1437,7 +1434,6 @@ docstring bformat(docstring const & fmt, long long arg1)
 #endif
 
 
-template<>
 docstring bformat(docstring const & fmt, unsigned int arg1)
 {
 	LATTEST(contains(fmt, from_ascii("%1$d")));
@@ -1446,8 +1442,7 @@ docstring bformat(docstring const & fmt, unsigned int arg1)
 }
 
 
-template<>
-docstring bformat(docstring const & fmt, docstring arg1)
+docstring bformat(docstring const & fmt, docstring const & arg1)
 {
 	LATTEST(contains(fmt, from_ascii("%1$s")));
 	docstring const str = subst(fmt, from_ascii("%1$s"), arg1);
@@ -1455,7 +1450,6 @@ docstring bformat(docstring const & fmt, docstring arg1)
 }
 
 
-template<>
 docstring bformat(docstring const & fmt, char * arg1)
 {
 	LATTEST(contains(fmt, from_ascii("%1$s")));
@@ -1464,8 +1458,7 @@ docstring bformat(docstring const & fmt, char * arg1)
 }
 
 
-template<>
-docstring bformat(docstring const & fmt, docstring arg1, docstring arg2)
+docstring bformat(docstring const & fmt, docstring const & arg1, docstring const & arg2)
 {
 	LATTEST(contains(fmt, from_ascii("%1$s")));
 	LATTEST(contains(fmt, from_ascii("%2$s")));
@@ -1475,8 +1468,7 @@ docstring bformat(docstring const & fmt, docstring arg1, docstring arg2)
 }
 
 
-template<>
-docstring bformat(docstring const & fmt, docstring arg1, int arg2)
+docstring bformat(docstring const & fmt, docstring const & arg1, int arg2)
 {
 	LATTEST(contains(fmt, from_ascii("%1$s")));
 	LATTEST(contains(fmt, from_ascii("%2$d")));
@@