Skip to content

Commit e04bbef

Browse files
committed
#188 Remove warnings from UserCallable implementation details
#189 Add -fPIC option for gcc build
1 parent accd07c commit e04bbef

File tree

3 files changed

+42
-14
lines changed

3 files changed

+42
-14
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ target_include_directories(${LIB_TARGET_NAME}
166166
if(JINJA2CPP_STRICT_WARNINGS)
167167
if(NOT MSVC)
168168
if (UNIX)
169-
target_compile_options(${LIB_TARGET_NAME} PRIVATE -Wall -Werror -Wno-unused-command-line-argument)
169+
target_compile_options(${LIB_TARGET_NAME} PRIVATE -Wall -Werror -Wno-unused-command-line-argument PUBLIC -fPIC)
170170
endif ()
171171
else ()
172172
target_compile_options(${LIB_TARGET_NAME} PRIVATE /W4)

include/jinja2cpp/user_callable.h

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,38 +20,64 @@ struct CanBeCalled : std::false_type {};
2020
template<typename T>
2121
struct CanBeCalled<T, typename std::enable_if<std::is_same<typename T::result_type, Value>::value>::type> : std::true_type {};
2222

23-
template<typename T>
23+
template<typename T, typename Tag = void>
2424
struct ArgPromoter
2525
{
26-
ArgPromoter(const T* val) : m_ptr(val) {}
26+
ArgPromoter(const T* val)
27+
: m_ptr(val)
28+
{
29+
}
2730

2831
operator T() const { return *m_ptr; }
2932

3033
const T* m_ptr;
3134
};
3235

3336
template<>
34-
struct ArgPromoter<EmptyValue>
37+
struct ArgPromoter<EmptyValue, void>
3538
{
3639
public:
3740
ArgPromoter(const EmptyValue*) {}
3841

3942
template<typename T>
40-
operator T() { return T(); }
43+
operator T()
44+
{
45+
return T();
46+
}
47+
};
48+
49+
template<typename T>
50+
struct ArgPromoter<T, std::enable_if_t<std::is_fundamental<T>::value>>
51+
{
52+
ArgPromoter(const T* val)
53+
: m_ptr(val)
54+
{
55+
}
56+
57+
template<typename U = T, typename = std::enable_if_t<std::is_convertible<T, U>::value>>
58+
operator U() const
59+
{
60+
return static_cast<U>(*m_ptr);
61+
}
62+
63+
const T* m_ptr;
4164
};
4265

4366
template<typename CharT>
44-
struct ArgPromoter<std::basic_string<CharT>>
67+
struct ArgPromoter<std::basic_string<CharT>, void>
4568
{
4669
using string = std::basic_string<CharT>;
4770
using string_view = nonstd::basic_string_view<CharT>;
4871
using other_string = std::conditional_t<std::is_same<CharT, char>::value, std::wstring, std::string>;
4972
using other_string_view = std::conditional_t<std::is_same<CharT, char>::value, nonstd::wstring_view, nonstd::string_view>;
5073

51-
ArgPromoter(const string* str) : m_ptr(str) {}
74+
ArgPromoter(const string* str)
75+
: m_ptr(str)
76+
{
77+
}
5278

5379
operator const string&() const { return *m_ptr; }
54-
operator string () const { return *m_ptr; }
80+
operator string() const { return *m_ptr; }
5581
operator string_view () const { return *m_ptr; }
5682
operator other_string () const
5783
{
@@ -68,17 +94,20 @@ struct ArgPromoter<std::basic_string<CharT>>
6894
};
6995

7096
template<typename CharT>
71-
struct ArgPromoter<nonstd::basic_string_view<CharT>>
97+
struct ArgPromoter<nonstd::basic_string_view<CharT>, void>
7298
{
7399
using string = std::basic_string<CharT>;
74100
using string_view = nonstd::basic_string_view<CharT>;
75101
using other_string = std::conditional_t<std::is_same<CharT, char>::value, std::wstring, std::string>;
76102
using other_string_view = std::conditional_t<std::is_same<CharT, char>::value, nonstd::wstring_view, nonstd::string_view>;
77103

78-
ArgPromoter(const string_view* str) : m_ptr(str) {}
104+
ArgPromoter(const string_view* str)
105+
: m_ptr(str)
106+
{
107+
}
79108

80-
operator const string_view& () const { return *m_ptr; }
81-
operator string_view () const { return *m_ptr; }
109+
operator const string_view&() const { return *m_ptr; }
110+
operator string_view() const { return *m_ptr; }
82111
operator string () const { return string(m_ptr->begin(), m_ptr->end()); }
83112
operator other_string () const
84113
{
@@ -132,7 +161,6 @@ struct UCInvoker
132161
{
133162
return Value();
134163
}
135-
136164
};
137165

138166
inline const Value& GetParamValue(const UserCallableParams& params, const ArgInfo& info)

src/value_visitors.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1020,7 +1020,7 @@ struct StringJoiner : BaseVisitor<TargetString>
10201020
std::enable_if_t<!std::is_same<CharT1, CharT2>::value, TargetString> operator() (std::basic_string<CharT1> left, const nonstd::basic_string_view<CharT2>& right) const
10211021
{
10221022
auto r = ConvertString<std::basic_string<CharT1>>(right);
1023-
left.append(right.begin(), right.end());
1023+
left.append(r.begin(), r.end());
10241024
return std::move(left);
10251025
}
10261026
};

0 commit comments

Comments
 (0)