Skip to content

Commit

Permalink
fix compilation warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
biojppm committed Apr 28, 2024
1 parent e08746e commit 95934a4
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
8 changes: 5 additions & 3 deletions samples/quickstart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
#include <string>
#include <iostream>

C4_SUPPRESS_WARNING_GCC_WITH_PUSH("-Wuseless-cast")
C4_SUPPRESS_WARNING_GCC_CLANG_PUSH
C4_SUPPRESS_WARNING_GCC("-Wuseless-cast")
C4_SUPPRESS_WARNING_GCC_CLANG("-Wold-style-cast")
C4_SUPPRESS_WARNING_MSVC_WITH_PUSH(4702) // unreachable code

using namespace c4::conf;
Expand Down Expand Up @@ -31,7 +33,7 @@ void setbar2(Tree &tree, csubstr bar2val);

// create the specs for the command line options to be handled by
// c4conf. These options will transform the config tree:
constexpr const ConfigActionSpec conf_specs[] = {
const ConfigActionSpec conf_specs[] = {
// using an explicit csubstr() is required by GCC5, but not with
// later versions, which will pick the proper csubstr constructor.
spec_for<ConfigAction::set_node> (csubstr("-cn" ), csubstr("--conf-node" )),
Expand Down Expand Up @@ -273,5 +275,5 @@ Given these default settings:
)";
}

C4_SUPPRESS_WARNING_GCC_POP
C4_SUPPRESS_WARNING_GCC_CLANG_POP
C4_SUPPRESS_WARNING_MSVC_POP
5 changes: 5 additions & 0 deletions src/c4/conf/conf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
#include <c4/fs/fs.hpp>
#include <c4/format.hpp>

C4_SUPPRESS_WARNING_GCC_CLANG_PUSH
C4_SUPPRESS_WARNING_GCC_CLANG("-Wold-style-cast")

#if 1 || defined(NDEBUG)
#define _pr(...)
#define _dbg(...)
Expand Down Expand Up @@ -602,3 +605,5 @@ size_t parse_opts(int *argc, char ***argv,

} // namespace conf
} // namespace c4

C4_SUPPRESS_WARNING_GCC_CLANG_POP
8 changes: 7 additions & 1 deletion src/c4/conf/conf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@
#include <c4/fs/fs.hpp>
#include <type_traits>



namespace c4 {
namespace conf {

using substr = c4::substr;
using csubstr = c4::csubstr;
using Tree = c4::yml::Tree;

C4_SUPPRESS_WARNING_GCC_CLANG_PUSH
C4_SUPPRESS_WARNING_GCC_CLANG("-Wold-style-cast")

//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
Expand Down Expand Up @@ -304,7 +308,7 @@ bool parse_opts(int *argc, char ***argv,


/** Parse command line options, and return a newly created container
* of with the result. Calls C4_ERROR() if the arguments fail to
* with the result. Calls C4_ERROR() if the arguments fail to
* parse. */
template<class ParsedOptContainer>
ParsedOptContainer parse_opts(int *argc, char ***argv, ConfigActionSpec const* specs, size_t num_specs)
Expand Down Expand Up @@ -410,6 +414,8 @@ C4_NO_INLINE void print_help(DumpFn &&dump,

/** @} */

C4_SUPPRESS_WARNING_GCC_CLANG_POP

} // namespace conf
} // namespace c4

Expand Down
7 changes: 7 additions & 0 deletions test/test_opts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
#include <vector>
#include <string>

C4_SUPPRESS_WARNING_GCC_CLANG_PUSH
C4_SUPPRESS_WARNING_GCC_CLANG("-Wold-style-cast")

namespace c4 {
namespace conf {

Expand Down Expand Up @@ -452,9 +455,11 @@ TEST_CASE("opts.github4")

void to_args(std::vector<std::string> const& stringvec, std::vector<char*> *args)
{
C4_SUPPRESS_WARNING_GCC_CLANG_WITH_PUSH("-Wcast-qual")
args->resize(stringvec.size());
for(size_t i = 0; i < stringvec.size(); ++i)
(*args)[i] = (char *)&(stringvec[i][0]);
C4_SUPPRESS_WARNING_GCC_CLANG_POP
}

size_t parse_opts(int *argc, char ***argv, c4::span<ParsedOpt> *opt_args, cspan<ConfigActionSpec> specs={})
Expand Down Expand Up @@ -545,3 +550,5 @@ void test_opts(std::vector<std::string> const& input_args,

} // namespace conf
} // namespace c4

C4_SUPPRESS_WARNING_GCC_CLANG_POP

0 comments on commit 95934a4

Please sign in to comment.