Skip to content

Commit 5838320

Browse files
authored
fix build with clang -std=c++20 (#216)
* apply llvm-namespace-comment * Make jinja2cpp compilable under clang 12 with -std=c++20 the problem arose from the fact that libfmt switched to consteval check of format string(that is great, but makes us obliged to provide format_to with constexpr format_string or fmt::runtime overload) unfortunatelly I couldn't make it work with constexpr std::string so multistringliteral returns std::basic_string_view except for cases where it needs std::string fix #213
1 parent af50a9c commit 5838320

21 files changed

+90
-48
lines changed

.github/workflows/linux-build.yml

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,16 @@ name: CI-linux-build
33

44
on:
55
push:
6+
branches:
7+
- master
8+
- main
69
paths-ignore:
710
- 'docs/**'
811
- '**.md'
912
pull_request:
13+
branches:
14+
- master
15+
- main
1016
paths-ignore:
1117
- 'docs/**'
1218
- '**.md'
@@ -96,7 +102,7 @@ jobs:
96102
fail-fast: false
97103
max-parallel: 8
98104
matrix:
99-
compiler: [10, 11]
105+
compiler: [10, 11, 12]
100106
base-flags: ["", -DJINJA2CPP_CXX_STANDARD=17]
101107
build-config: [Release, Debug]
102108
build-shared: [TRUE, FALSE]
@@ -106,6 +112,9 @@ jobs:
106112
docker-image: conanio/clang10
107113
- compiler: 11
108114
docker-image: conanio/clang11
115+
- compiler: 12
116+
docker-image: conanio/clang12-ubuntu16.04:1.39.0
117+
109118

110119
steps:
111120
- uses: actions/checkout@v1
@@ -119,12 +128,17 @@ jobs:
119128
INPUT_BUILD_SHARED: ${{ matrix.build-shared }}
120129
HOME: /home/conan
121130
run: |
131+
#!/bin/bash
122132
set -ex
123133
export BUILD_TARGET=all
124134
export CMAKE_OPTS=-DCMAKE_VERBOSE_MAKEFILE=OFF
125135
export BUILD_CONFIG=${INPUT_BASE_CONFIG}
126136
export WORKSPACE=$GITHUB_WORKSPACE
127-
$CXX --version
137+
#if [ "${INPUT_COMPILER}" != "" ]; then export CXX=${INPUT_COMPILER}; fi
138+
if [ "${INPUT_COMPILER}" == "clang-12" ] ; then
139+
export INPUT_BASE_FLAGS="-DJINJA2CPP_CXX_STANDARD=20" ;
140+
fi
141+
#$CXX --version
128142
export EXTRA_FLAGS="${INPUT_BASE_FLAGS} ${INPUT_EXTRA_FLAGS}"
129143
mkdir $BUILD_DIRECTORY && cd $BUILD_DIRECTORY
130144
sudo chmod gou+rw -R $WORKSPACE

.github/workflows/windows-build.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,16 @@ name: CI-windows-build
22

33
on:
44
push:
5+
branches:
6+
- master
7+
- main
58
paths-ignore:
69
- 'docs/**'
710
- '**.md'
811
pull_request:
12+
branches:
13+
- master
14+
- main
915
paths-ignore:
1016
- 'docs/**'
1117
- '**.md'

src/error_info.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,12 @@ struct ValueRenderer
1818
{
1919
}
2020

21-
void operator()(bool val) const { fmt::format_to(ctx->out(), (val ? UNIVERSAL_STR("True") : UNIVERSAL_STR("False")).GetValue<CharT>()); }
21+
constexpr void operator()(bool val) const {
22+
fmt::format_to(
23+
ctx->out(),
24+
UNIVERSAL_STR("{}").GetValue<CharT>(),
25+
(val ? UNIVERSAL_STR("True").GetValue<CharT>(): UNIVERSAL_STR("False").GetValue<CharT>()));
26+
}
2227
void operator()(const jinja2::EmptyValue&) const { fmt::format_to(ctx->out(), UNIVERSAL_STR("").GetValue<CharT>()); }
2328
template<typename CharU>
2429
void operator()(const std::basic_string<CharU>& val) const
@@ -83,7 +88,7 @@ struct ValueRenderer
8388
fmt::format_to(ctx->out(), UNIVERSAL_STR("{}").GetValue<CharT>(), val);
8489
}
8590
};
86-
}
91+
} // namespace
8792

8893
namespace fmt
8994
{
@@ -103,7 +108,7 @@ struct formatter<jinja2::Value, CharT>
103108
return fmt::format_to(ctx.out(), UNIVERSAL_STR("").GetValue<CharT>());
104109
}
105110
};
106-
}
111+
} // namespace fmt
107112

108113
namespace jinja2
109114
{
@@ -281,4 +286,4 @@ std::wostream& operator << (std::wostream& os, const ErrorInfoW& res)
281286
os << res.ToString();
282287
return os;
283288
}
284-
} // jinja2
289+
} // namespace jinja2

src/expression_evaluator.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -596,5 +596,5 @@ CallParams EvaluateCallParams(const CallParamsInfo& info, RenderContext& context
596596
return result;
597597
}
598598

599-
}
600-
}
599+
} // namespace helpers
600+
} // namespace jinja2

src/expression_parser.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -603,4 +603,4 @@ ExpressionParser::ParseResult<ExpressionEvaluatorPtr<IfExpression>> ExpressionPa
603603
return result;
604604
}
605605

606-
} // jinja2
606+
} // namespace jinja2

src/filesystem_handler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,4 +144,4 @@ CharFileStreamPtr RealFileSystem::OpenByteStream(const std::string& name) const
144144
return CharFileStreamPtr(nullptr, [](std::istream*){});
145145
}
146146

147-
} // jinja2
147+
} // namespace jinja2

src/filters.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1082,5 +1082,5 @@ InternalValue UserDefinedFilter::Filter(const InternalValue& baseVal, RenderCont
10821082
return callable->GetExpressionCallable()(callParams, context);
10831083
}
10841084

1085-
} // filters
1086-
} // jinja2
1085+
} // namespace filters
1086+
} // namespace jinja2

src/helpers.h

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,27 @@ struct MultiStringLiteral
1515
const char* charValue;
1616
const wchar_t* wcharValue;
1717

18+
constexpr MultiStringLiteral(const char* val, const wchar_t* wval)
19+
: charValue(val)
20+
, wcharValue(wval)
21+
{
22+
}
23+
24+
template<typename CharT>
25+
constexpr auto GetValue() const
26+
{
27+
#if __cplusplus < 202002L
28+
return GetValueStr<CharT>();
29+
#else
30+
constexpr auto memPtr = SelectMemberPtr<CharT, &MultiStringLiteral::charValue, &MultiStringLiteral::wcharValue>::GetPtr();
31+
return nonstd::basic_string_view<CharT>(this->*memPtr);
32+
#endif
33+
}
34+
1835
template<typename CharT>
19-
auto GetValue() const
36+
constexpr auto GetValueStr() const
2037
{
21-
auto memPtr = SelectMemberPtr<CharT, &MultiStringLiteral::charValue, &MultiStringLiteral::wcharValue>::GetPtr();
38+
constexpr auto memPtr = SelectMemberPtr<CharT, &MultiStringLiteral::charValue, &MultiStringLiteral::wcharValue>::GetPtr();
2239
return std::basic_string<CharT>(this->*memPtr);
2340
}
2441

@@ -28,13 +45,13 @@ struct MultiStringLiteral
2845
template<const char* (MultiStringLiteral::*charMemPtr), const wchar_t* (MultiStringLiteral::*wcharMemPtr)>
2946
struct SelectMemberPtr<char, charMemPtr, wcharMemPtr>
3047
{
31-
static auto GetPtr() {return charMemPtr;}
48+
static constexpr auto GetPtr() {return charMemPtr;}
3249
};
3350

3451
template<const char* (MultiStringLiteral::*charMemPtr), const wchar_t* (MultiStringLiteral::*wcharMemPtr)>
3552
struct SelectMemberPtr<wchar_t, charMemPtr, wcharMemPtr>
3653
{
37-
static auto GetPtr() {return wcharMemPtr;}
54+
static constexpr auto GetPtr() {return wcharMemPtr;}
3855
};
3956

4057
template<typename CharT>

src/internal_value.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -859,6 +859,6 @@ InputValueConvertor::result_t InputValueConvertor::ConvertUserCallable(const Use
859859
}));
860860
}
861861

862-
} // visitors
862+
} // namespace visitors
863863

864-
} // jinja2
864+
} // namespace jinja2

src/lexer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,4 +119,4 @@ bool Lexer::ProcessString(const lexertk::token&, Token& newToken)
119119
return true;
120120
}
121121

122-
} // jinja2
122+
} // namespace jinja2

0 commit comments

Comments
 (0)