Skip to content

Commit 138b7f1

Browse files
committed
fix some warnings with clang
1 parent d5d7758 commit 138b7f1

6 files changed

Lines changed: 85 additions & 49 deletions

File tree

include/MGIS/LogStream.hxx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,14 @@ namespace mgis {
7878
* \param[in] c: color
7979
* \note this only works on the terminal
8080
*/
81-
MGIS_EXPORT bool setStreamColor(std::ostream &,
81+
MGIS_EXPORT void setStreamColor(std::ostream &,
8282
const OutputStreamColors) noexcept;
8383
/*!
8484
* \brief reset the color of the output
8585
* \param[out] out: output stream
8686
* \param[in] l: verbosity level
8787
*/
88-
MGIS_EXPORT bool resetStreamColor(std::ostream &) noexcept;
88+
MGIS_EXPORT void resetStreamColor(std::ostream &) noexcept;
8989
/*!
9090
* \brief print a warning message
9191
*
@@ -103,6 +103,9 @@ namespace mgis {
103103
template <typename... Args>
104104
void debug(std::ostream &, Args &&...) noexcept;
105105

106+
MGIS_EXPORT void setErrorColor(std::ostream &) noexcept;
107+
MGIS_EXPORT void setWarningColor(std::ostream &) noexcept;
108+
106109
} // end of namespace mgis
107110

108111
#include "MGIS/LogStream.ixx"

include/MGIS/Utilities/Construct.hxx

Lines changed: 52 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@
105105
if (!MGIS_TEMPORARY_VARIABLE(v).has_value()) { \
106106
return InvalidResult{}; \
107107
} \
108-
Type &v = *(MGIS_TEMPORARY_VARIABLE(v));
108+
Type& v = *(MGIS_TEMPORARY_VARIABLE(v))
109109

110110
/*!
111111
* \brief an helper macro to build an unique pointer for type the constructor of
@@ -119,7 +119,8 @@
119119
std::unique_ptr<Type> v = MGIS_MAKE_UNIQUE(Type, e, __VA_ARGS__); \
120120
if (v.get() == nullptr) { \
121121
return InvalidResult{}; \
122-
}
122+
} \
123+
static_cast<void>(0)
123124

124125
/*!
125126
* \brief an helper macro to build an unique pointer for type the constructor of
@@ -135,7 +136,8 @@
135136
MGIS_MAKE_UNIQUE_AS(BaseType, Type, e, __VA_ARGS__); \
136137
if (v.get() == nullptr) { \
137138
return InvalidResult{}; \
138-
}
139+
} \
140+
static_cast<void>(0)
139141

140142
/*!
141143
* \brief an helper macro to build an shared pointer for type the constructor of
@@ -149,7 +151,8 @@
149151
std::shared_ptr<Type> v = MGIS_MAKE_SHARED(Type, e, __VA_ARGS__); \
150152
if (v.get() == nullptr) { \
151153
return InvalidResult{}; \
152-
}
154+
} \
155+
static_cast<void>(0)
153156

154157
/*!
155158
* \brief an helper macro to build an shared pointer for type the constructor of
@@ -165,7 +168,8 @@
165168
MGIS_MAKE_SHARED_AS(BaseType, Type, e, __VA_ARGS__); \
166169
if (v.get() == nullptr) { \
167170
return InvalidResult{}; \
168-
}
171+
} \
172+
static_cast<void>(0)
169173

170174
namespace mgis {
171175

@@ -184,11 +188,11 @@ namespace mgis {
184188
* \param[in] args: arguments passed to the constructor
185189
*/
186190
template <typename Type, typename... ArgumentsTypes>
187-
[[nodiscard]] std::optional<Type> construct(
188-
Context &,
189-
const std::source_location &,
190-
ArgumentsTypes &&...) noexcept requires
191-
std::is_constructible_v<std::remove_const_t<Type>, ArgumentsTypes...>;
191+
[[nodiscard]] std::optional<Type> construct(Context&,
192+
const std::source_location&,
193+
ArgumentsTypes&&...) noexcept
194+
requires std::is_constructible_v<std::remove_const_t<Type>,
195+
ArgumentsTypes...>;
192196
/*!
193197
* \brief try to build a unique pointer holding the given type.
194198
*
@@ -203,11 +207,11 @@ namespace mgis {
203207
* \param[in] args: arguments passed to the constructor
204208
*/
205209
template <typename Type, typename... ArgumentsTypes>
206-
[[nodiscard]] std::unique_ptr<Type> make_unique(
207-
Context &,
208-
const std::source_location &,
209-
ArgumentsTypes &&...) noexcept requires
210-
std::is_constructible_v<std::remove_const_t<Type>, ArgumentsTypes...>;
210+
[[nodiscard]] std::unique_ptr<Type> make_unique(Context&,
211+
const std::source_location&,
212+
ArgumentsTypes&&...) noexcept
213+
requires std::is_constructible_v<std::remove_const_t<Type>,
214+
ArgumentsTypes...>;
211215
/*!
212216
* \brief try to build a unique pointer of a base type holding the given type.
213217
*
@@ -223,9 +227,10 @@ namespace mgis {
223227
*/
224228
template <typename BaseType, typename Type, typename... ArgumentsTypes>
225229
[[nodiscard]] std::unique_ptr<BaseType> make_unique_as(
226-
Context &, const std::source_location &, ArgumentsTypes &&...) noexcept
227-
requires std::is_base_of_v<BaseType, Type> &&
228-
std::is_constructible_v<std::remove_const_t<Type>, ArgumentsTypes...>;
230+
Context&, const std::source_location&, ArgumentsTypes&&...) noexcept
231+
requires std::is_base_of_v<BaseType, Type> &&
232+
std::is_constructible_v<std::remove_const_t<Type>,
233+
ArgumentsTypes...>;
229234
/*!
230235
* \brief try to build a shared pointer holding the given type.
231236
*
@@ -239,11 +244,11 @@ namespace mgis {
239244
* \param[in] args: arguments passed to the constructor
240245
*/
241246
template <typename Type, typename... ArgumentsTypes>
242-
[[nodiscard]] std::shared_ptr<Type> make_shared(
243-
Context &,
244-
const std::source_location &,
245-
ArgumentsTypes &&...) noexcept requires
246-
std::is_constructible_v<std::remove_const_t<Type>, ArgumentsTypes...>;
247+
[[nodiscard]] std::shared_ptr<Type> make_shared(Context&,
248+
const std::source_location&,
249+
ArgumentsTypes&&...) noexcept
250+
requires std::is_constructible_v<std::remove_const_t<Type>,
251+
ArgumentsTypes...>;
247252
/*!
248253
* \brief try to build a shared pointer of a base type holding the given type.
249254
*
@@ -259,9 +264,10 @@ namespace mgis {
259264
*/
260265
template <typename BaseType, typename Type, typename... ArgumentsTypes>
261266
[[nodiscard]] std::shared_ptr<BaseType> make_shared_as(
262-
Context &, const std::source_location &, ArgumentsTypes &&...) noexcept
263-
requires std::is_base_of_v<BaseType, Type> &&
264-
std::is_constructible_v<std::remove_const_t<Type>, ArgumentsTypes...>;
267+
Context&, const std::source_location&, ArgumentsTypes&&...) noexcept
268+
requires std::is_base_of_v<BaseType, Type> &&
269+
std::is_constructible_v<std::remove_const_t<Type>,
270+
ArgumentsTypes...>;
265271

266272
#endif
267273

@@ -278,9 +284,10 @@ namespace mgis {
278284
* \param[in] args: arguments passed to the constructor
279285
*/
280286
template <typename Type, typename... ArgumentsTypes>
281-
[[nodiscard]] std::optional<Type> construct(
282-
Context &, ArgumentsTypes &&...) noexcept requires
283-
std::is_constructible_v<std::remove_const_t<Type>, ArgumentsTypes...>;
287+
[[nodiscard]] std::optional<Type> construct(Context&,
288+
ArgumentsTypes&&...) noexcept
289+
requires std::is_constructible_v<std::remove_const_t<Type>,
290+
ArgumentsTypes...>;
284291
/*!
285292
* \brief try to build a unique pointer holding the given type.
286293
*
@@ -295,9 +302,10 @@ namespace mgis {
295302
* \param[in] args: arguments passed to the constructor
296303
*/
297304
template <typename Type, typename... ArgumentsTypes>
298-
[[nodiscard]] std::unique_ptr<Type> make_unique(
299-
Context &, ArgumentsTypes &&...) noexcept requires
300-
std::is_constructible_v<std::remove_const_t<Type>, ArgumentsTypes...>;
305+
[[nodiscard]] std::unique_ptr<Type> make_unique(Context&,
306+
ArgumentsTypes&&...) noexcept
307+
requires std::is_constructible_v<std::remove_const_t<Type>,
308+
ArgumentsTypes...>;
301309
/*!
302310
* \brief try to build a unique pointer of a base type holding the given type.
303311
*
@@ -313,9 +321,10 @@ namespace mgis {
313321
*/
314322
template <typename BaseType, typename Type, typename... ArgumentsTypes>
315323
[[nodiscard]] std::unique_ptr<BaseType> make_unique_as(
316-
Context &, ArgumentsTypes &&...) noexcept requires
317-
std::is_base_of_v<BaseType, Type> &&
318-
std::is_constructible_v<std::remove_const_t<Type>, ArgumentsTypes...>;
324+
Context&, ArgumentsTypes&&...) noexcept
325+
requires std::is_base_of_v<BaseType, Type> &&
326+
std::is_constructible_v<std::remove_const_t<Type>,
327+
ArgumentsTypes...>;
319328
/*!
320329
* \brief try to build a shared pointer holding the given type.
321330
*
@@ -329,9 +338,10 @@ namespace mgis {
329338
* \param[in] args: arguments passed to the constructor
330339
*/
331340
template <typename Type, typename... ArgumentsTypes>
332-
[[nodiscard]] std::shared_ptr<Type> make_shared(
333-
Context &, ArgumentsTypes &&...) noexcept requires
334-
std::is_constructible_v<std::remove_const_t<Type>, ArgumentsTypes...>;
341+
[[nodiscard]] std::shared_ptr<Type> make_shared(Context&,
342+
ArgumentsTypes&&...) noexcept
343+
requires std::is_constructible_v<std::remove_const_t<Type>,
344+
ArgumentsTypes...>;
335345
/*!
336346
* \brief try to build a shared pointer of a base type holding the given type.
337347
*
@@ -347,9 +357,10 @@ namespace mgis {
347357
*/
348358
template <typename BaseType, typename Type, typename... ArgumentsTypes>
349359
[[nodiscard]] std::shared_ptr<BaseType> make_shared_as(
350-
Context &, ArgumentsTypes &&...) noexcept requires
351-
std::is_base_of_v<BaseType, Type> &&
352-
std::is_constructible_v<std::remove_const_t<Type>, ArgumentsTypes...>;
360+
Context&, ArgumentsTypes&&...) noexcept
361+
requires std::is_base_of_v<BaseType, Type> &&
362+
std::is_constructible_v<std::remove_const_t<Type>,
363+
ArgumentsTypes...>;
353364

354365
} // end of namespace mgis
355366

include/MGIS/Utilities/Construct.ixx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,4 +218,4 @@ namespace mgis {
218218

219219
} // namespace mgis
220220

221-
#endif /* LIB_MGIS_UTILITIES_CONSTRUCT_IXX */
221+
#endif /* LIB_MGIS_UTILITIES_CONSTRUCT_IXX */

include/MGIS/Utilities/Invoke.ixx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,4 +159,4 @@ namespace mgis {
159159

160160
} // end of namespace mgis
161161

162-
#endif /* LIB_MGIS_UTILITIES_INVOKE_IXX */
162+
#endif /* LIB_MGIS_UTILITIES_INVOKE_IXX */

src/LogStream.cxx

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,28 @@ namespace mgis {
158158
static constexpr char Reset[4] = {033, '[', 'm', 017};
159159
};
160160

161+
void setStreamColor(std::ostream &os, const OutputStreamColors c) noexcept {
162+
if (c == OutputStreamColors::BLACK) {
163+
os.write(TerminalColors::Black, sizeof(TerminalColors::Black));
164+
} else if (c == OutputStreamColors::RED) {
165+
os.write(TerminalColors::Red, sizeof(TerminalColors::Red));
166+
} else if (c == OutputStreamColors::GREEN) {
167+
os.write(TerminalColors::Green, sizeof(TerminalColors::Green));
168+
} else if (c == OutputStreamColors::YELLOW) {
169+
os.write(TerminalColors::Yellow, sizeof(TerminalColors::Yellow));
170+
} else if (c == OutputStreamColors::BLUE) {
171+
os.write(TerminalColors::Blue, sizeof(TerminalColors::Blue));
172+
} else if (c == OutputStreamColors::PURPLE) {
173+
os.write(TerminalColors::Purple, sizeof(TerminalColors::Purple));
174+
} else if (c == OutputStreamColors::LIGHTBLUE) {
175+
os.write(TerminalColors::LightBlue, sizeof(TerminalColors::LightBlue));
176+
} else if (c == OutputStreamColors::WHITE) {
177+
os.write(TerminalColors::White, sizeof(TerminalColors::White));
178+
} else if (c == OutputStreamColors::RESET) {
179+
os.write(TerminalColors::Reset, sizeof(TerminalColors::Reset));
180+
}
181+
} // end of setStreamColor
182+
161183
void setErrorColor(std::ostream &os) noexcept {
162184
os.write(TerminalColors::Red, sizeof(TerminalColors::Red));
163185
}
@@ -166,8 +188,8 @@ namespace mgis {
166188
os.write(TerminalColors::LightBlue, sizeof(TerminalColors::LightBlue));
167189
}
168190

169-
void resetOutputColor(std::ostream &os) noexcept {
191+
void resetStreamColor(std::ostream &os) noexcept {
170192
os.write(TerminalColors::Reset, sizeof(TerminalColors::Reset));
171193
}
172194

173-
} // end of namespace mgis
195+
} // end of namespace mgis

tests/InvokeTest.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,14 @@ struct InvokeTest final : public tfel::tests::TestCase {
6969
const auto r1 =
7070
invokeCheckErrno(ctx, static_cast<double (*)(double)>(std::log), 1);
7171
TFEL_TESTS_ASSERT(r1.has_value());
72-
TFEL_TESTS_CHECK_EQUAL(*r1, 0);
72+
TFEL_TESTS_ASSERT(std::abs(*r1) < 1e-14);
7373
const auto r2 =
7474
invokeCheckErrno(ctx, static_cast<double (*)(double)>(std::log), -1);
7575
TFEL_TESTS_ASSERT(!r2.has_value());
7676
const auto r3 = MGIS_INVOKE_CHECK_ERRNO(
7777
ctx, static_cast<double (*)(double)>(std::log), 1);
7878
TFEL_TESTS_ASSERT(r3.has_value());
79-
TFEL_TESTS_CHECK_EQUAL(*r3, 0);
79+
TFEL_TESTS_ASSERT(std::abs(*r3) < 1e-14);
8080
const auto r4 = MGIS_INVOKE_CHECK_ERRNO(
8181
ctx, static_cast<double (*)(double)>(std::log), -1);
8282
TFEL_TESTS_ASSERT(!r4.has_value());

0 commit comments

Comments
 (0)