Skip to content

Commit

Permalink
fix: #158 Merge branch 'gcc-wshadow'
Browse files Browse the repository at this point in the history
The -Wshadow warning is avoided from the source code level
  • Loading branch information
ToruNiina committed May 10, 2021
2 parents 06e8b85 + 7e90282 commit c5a22b9
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 73 deletions.
6 changes: 3 additions & 3 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ CHECK_CXX_COMPILER_FLAG("-Wuseless-cast" COMPILER_SUPPORTS_WUSELESS_CAST)
CHECK_CXX_COMPILER_FLAG("-Wdouble-promotion" COMPILER_SUPPORTS_WDOUBLE_PROMOTION)
CHECK_CXX_COMPILER_FLAG("-Wrange-loop-analysis" COMPILER_SUPPORTS_WRANGE_LOOP_ANALYSIS)
CHECK_CXX_COMPILER_FLAG("-Wundef" COMPILER_SUPPORTS_WUNDEF)
CHECK_CXX_COMPILER_FLAG("-Wshadow=local" COMPILER_SUPPORTS_WSHADOW_LOCAL)
CHECK_CXX_COMPILER_FLAG("-Wshadow" COMPILER_SUPPORTS_WSHADOW)

if(COMPILER_SUPPORTS_WALL)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
Expand All @@ -73,8 +73,8 @@ endif()
if(COMPILER_SUPPORTS_WERROR)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
endif()
if(COMPILER_SUPPORTS_WSHADOW_LOCAL)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wshadow=local")
if(COMPILER_SUPPORTS_WSHADOW)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wshadow")
endif()
if(COMPILER_SUPPORTS_WSIGN_CONVERSION)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wsign-conversion")
Expand Down
20 changes: 10 additions & 10 deletions toml/region.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,13 @@ struct location final : public region_base
using difference_type = typename const_iterator::difference_type;
using source_ptr = std::shared_ptr<const std::vector<char>>;

location(std::string name, std::vector<char> cont)
location(std::string source_name, std::vector<char> cont)
: source_(std::make_shared<std::vector<char>>(std::move(cont))),
line_number_(1), source_name_(std::move(name)), iter_(source_->cbegin())
line_number_(1), source_name_(std::move(source_name)), iter_(source_->cbegin())
{}
location(std::string name, const std::string& cont)
location(std::string source_name, const std::string& cont)
: source_(std::make_shared<std::vector<char>>(cont.begin(), cont.end())),
line_number_(1), source_name_(std::move(name)), iter_(source_->cbegin())
line_number_(1), source_name_(std::move(source_name)), iter_(source_->cbegin())
{}

location(const location&) = default;
Expand Down Expand Up @@ -343,9 +343,9 @@ struct region final : public region_base
}))
{
// unwrap the first '#' by std::next.
auto str = make_string(std::next(comment_found), iter);
if(!str.empty() && str.back() == '\r') {str.pop_back();}
com.push_back(std::move(str));
auto s = make_string(std::next(comment_found), iter);
if(!s.empty() && s.back() == '\r') {s.pop_back();}
com.push_back(std::move(s));
}
else
{
Expand Down Expand Up @@ -396,9 +396,9 @@ struct region final : public region_base
}))
{
// unwrap the first '#' by std::next.
auto str = make_string(std::next(comment_found), this->line_end());
if(!str.empty() && str.back() == '\r') {str.pop_back();}
com.push_back(std::move(str));
auto s = make_string(std::next(comment_found), this->line_end());
if(!s.empty() && s.back() == '\r') {s.pop_back();}
com.push_back(std::move(s));
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions toml/serializer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,19 @@ namespace toml
// a `"` and escaping some special character is boring.
template<typename charT, typename traits, typename Alloc>
std::basic_string<charT, traits, Alloc>
format_key(const std::basic_string<charT, traits, Alloc>& key)
format_key(const std::basic_string<charT, traits, Alloc>& k)
{
// check the key can be a bare (unquoted) key
detail::location loc(key, std::vector<char>(key.begin(), key.end()));
detail::location loc(k, std::vector<char>(k.begin(), k.end()));
detail::lex_unquoted_key::invoke(loc);
if(loc.iter() == loc.end())
{
return key; // all the tokens are consumed. the key is unquoted-key.
return k; // all the tokens are consumed. the key is unquoted-key.
}

//if it includes special characters, then format it in a "quoted" key.
std::basic_string<charT, traits, Alloc> serialized("\"");
for(const char c : key)
for(const char c : k)
{
switch(c)
{
Expand Down
23 changes: 23 additions & 0 deletions toml/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ class basic_value;
using character = char;
using key = std::string;

#if !defined(__clang__) && defined(__GNUC__) && __GNUC__ <= 4
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wshadow"
#endif

using boolean = bool;
using integer = std::int64_t;
using floating = double; // "float" is a keyward, cannot use it here.
Expand All @@ -32,12 +37,26 @@ using floating = double; // "float" is a keyward, cannot use it here.
// - local_date
// - local_time

#if defined(__GNUC__) && !defined(__clang__)
# pragma GCC diagnostic pop
#endif

// default toml::value and default array/table. these are defined after defining
// basic_value itself.
// using value = basic_value<discard_comments, std::unordered_map, std::vector>;
// using array = typename value::array_type;
// using table = typename value::table_type;

// to avoid warnings about `value_t::integer` is "shadowing" toml::integer in
// GCC -Wshadow=global.
#if defined(__GNUC__) && !defined(__clang__)
# pragma GCC diagnostic push
# if 7 <= __GNUC__
# pragma GCC diagnostic ignored "-Wshadow=global"
# else // gcc-6 or older
# pragma GCC diagnostic ignored "-Wshadow"
# endif
#endif
enum class value_t : std::uint8_t
{
empty = 0,
Expand All @@ -52,6 +71,9 @@ enum class value_t : std::uint8_t
array = 9,
table = 10,
};
#if defined(__GNUC__) && !defined(__clang__)
# pragma GCC diagnostic pop
#endif

template<typename charT, typename traits>
inline std::basic_ostream<charT, traits>&
Expand Down Expand Up @@ -147,4 +169,5 @@ template<typename T, typename V> struct is_exact_toml_type<T const volatile&, V>

} // detail
} // toml

#endif// TOML11_TYPES_H
Loading

0 comments on commit c5a22b9

Please sign in to comment.