Skip to content

Commit

Permalink
Fix GCC -Wshadow-local and MSVC C4457
Browse files Browse the repository at this point in the history
  • Loading branch information
Kojoley committed May 17, 2021
1 parent 0e15dd1 commit db8bdf3
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 36 deletions.
1 change: 0 additions & 1 deletion .appveyor.yml
Expand Up @@ -56,7 +56,6 @@ before_build:
-wd4996 # Call to 'std::copy' with parameters that may be unsafe
-wd4100 # unreferenced formal parameter
-wd4310 # cast truncates constant value
-wd4457 # declaration of 'varname' hides function parameter
-wd4458 # declaration of 'varname' hides class member
-wd4459 # declaration of 'varname' hides global declaration
-wd4512 # assignment operator could not be generated
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/ci.yml
Expand Up @@ -413,6 +413,11 @@ jobs:
variant sanitize : <optimization>speed <debug-symbols>off <inlining>full
<runtime-debugging>off ;
# Enable additional warnings
toolset.flags gcc.compile OPTIONS <warnings>extra :
-Wshadow-local
: unchecked ;
# Ignore some warnings
feature.feature known-warnings : suppress : optional incidental propagated ;
toolset.flags gcc.compile OPTIONS <known-warnings>suppress :
Expand Down
5 changes: 5 additions & 0 deletions .travis.yml
Expand Up @@ -107,6 +107,11 @@ before_install:
variant sanitize : <optimization>speed <debug-symbols>off <inlining>full
<runtime-debugging>off ;
# Enable additional warnings
toolset.flags gcc.compile OPTIONS <warnings>extra :
-Wshadow-local
: unchecked ;
# Ignore some warnings
feature.feature known-warnings : suppress : optional incidental propagated ;
toolset.flags gcc.compile OPTIONS <known-warnings>suppress :
Expand Down
Expand Up @@ -523,21 +523,21 @@ class basic_re_tokeniser_helper

for (; start_ <= end_; ++start_)
{
CharT ch_ = static_cast<CharT> (start_);
CharT ch_i = static_cast<CharT> (start_);

if ((state_._flags & icase) &&
(std::isupper (ch_, state_._locale) ||
std::islower (ch_, state_._locale)))
(std::isupper (ch_i, state_._locale) ||
std::islower (ch_i, state_._locale)))
{
CharT upper_ = std::toupper (ch_, state_._locale);
CharT lower_ = std::tolower (ch_, state_._locale);
CharT upper_ = std::toupper (ch_i, state_._locale);
CharT lower_ = std::tolower (ch_i, state_._locale);

chars_ += (upper_);
chars_ += (lower_);
}
else
{
chars_ += (ch_);
chars_ += (ch_i);
}
}
}
Expand Down
14 changes: 7 additions & 7 deletions test/x3/debug.cpp
Expand Up @@ -68,9 +68,9 @@ main()

{ // basic tests

auto a = rule<class a>("a") = 'a';
auto b = rule<class b>("b") = 'b';
auto c = rule<class c>("c") = 'c';
auto a = rule<class a_id>("a") = 'a';
auto b = rule<class b_id>("b") = 'b';
auto c = rule<class c_id>("c") = 'c';

{
auto start = *(a | b | c);
Expand All @@ -89,9 +89,9 @@ main()

{ // basic tests w/ skipper

auto a = rule<class a>("a") = 'a';
auto b = rule<class b>("b") = 'b';
auto c = rule<class c>("c") = 'c';
auto a = rule<class a_id>("a") = 'a';
auto b = rule<class b_id>("b") = 'b';
auto c = rule<class c_id>("c") = 'c';

{
auto start = *(a | b | c);
Expand Down Expand Up @@ -133,7 +133,7 @@ main()
{
symbols<my_attribute> a{{{ "a", my_attribute{} }}};

auto b = rule<struct b, my_attribute>("b") = a;
auto b = rule<struct b_id, my_attribute>("b") = a;

my_attribute attr;

Expand Down
8 changes: 4 additions & 4 deletions test/x3/rule1.cpp
Expand Up @@ -92,17 +92,17 @@ main()

{ // basic tests w/ skipper but no final post-skip

auto a = rule<class a>()
auto a = rule<class a_id>()
= lit('a');

auto b = rule<class b>()
auto b = rule<class b_id>()
= lit('b');

auto c = rule<class c>()
auto c = rule<class c_id>()
= lit('c');

{
auto start = rule<class start>() = *(a | b) >> c;
auto start = rule<class start_id>() = *(a | b) >> c;

char const *s1 = " a b a a b b a c ... "
, *const e1 = s1 + std::strlen(s1);
Expand Down
10 changes: 5 additions & 5 deletions test/x3/rule2.cpp
Expand Up @@ -47,7 +47,7 @@ main()
{ // context tests

char ch;
auto a = rule<class a, char>() = alpha;
auto a = rule<class a_id, char>() = alpha;

// this semantic action requires the context
auto f = [&](auto& ctx){ ch = _attr(ctx); };
Expand All @@ -71,7 +71,7 @@ main()
{ // auto rules tests

char ch = '\0';
auto a = rule<class a, char>() = alpha;
auto a = rule<class a_id, char>() = alpha;
auto f = [&](auto& ctx){ ch = _attr(ctx); };

BOOST_TEST(test("x", a[f]));
Expand All @@ -98,7 +98,7 @@ main()
auto f = [&](auto& ctx){ s = _attr(ctx); };

{
auto r = rule<class r, std::string>()
auto r = rule<class r_id, std::string>()
= char_ >> *(',' >> char_)
;

Expand All @@ -107,15 +107,15 @@ main()
}

{
auto r = rule<class r, std::string>()
auto r = rule<class r_id, std::string>()
= char_ >> *(',' >> char_);
s.clear();
BOOST_TEST(test("a,b,c,d,e,f", r[f]));
BOOST_TEST(s == "abcdef");
}

{
auto r = rule<class r, std::string>()
auto r = rule<class r_id, std::string>()
= char_ >> char_ >> char_ >> char_ >> char_ >> char_;
s.clear();
BOOST_TEST(test("abcdef", r[f]));
Expand Down
2 changes: 1 addition & 1 deletion test/x3/rule3.cpp
Expand Up @@ -138,7 +138,7 @@ int main()
}

{
auto r = rule<class r, int>{} = eps[([] (auto& ctx) {
auto r = rule<class r_id, int>{} = eps[([] (auto& ctx) {
using boost::spirit::x3::_val;
static_assert(std::is_same<std::decay_t<decltype(_val(ctx))>, unused_type>::value,
"Attribute must not be synthesized");
Expand Down
8 changes: 4 additions & 4 deletions test/x3/rule4.cpp
Expand Up @@ -95,7 +95,7 @@ main()

// test deduced auto rule behavior

auto text = rule<class text, std::string>()
auto text = rule<class text_id, std::string>()
= +(!char_(')') >> !char_('>') >> char_);

attr.clear();
Expand All @@ -119,14 +119,14 @@ main()

{
typedef boost::variant<double, int> v_type;
auto r1 = rule<class r1, v_type>()
auto r1 = rule<class r1_id, v_type>()
= int_;
v_type v;
BOOST_TEST(test_attr("1", r1, v) && v.which() == 1 &&
boost::get<int>(v) == 1);

typedef boost::optional<int> ov_type;
auto r2 = rule<class r2, ov_type>()
auto r2 = rule<class r2_id, ov_type>()
= int_;
ov_type ov;
BOOST_TEST(test_attr("1", r2, ov) && ov && boost::get<int>(ov) == 1);
Expand All @@ -136,7 +136,7 @@ main()
{
using boost::fusion::vector;
using boost::fusion::at_c;
auto r = rule<class r, vector<int>>()
auto r = rule<class r_id, vector<int>>()
= int_;

vector<int> v(0);
Expand Down
16 changes: 8 additions & 8 deletions test/x3/sequence.cpp
Expand Up @@ -149,7 +149,7 @@ main()
typedef deque<char, int> attr_type;
attr_type fv;

auto r = rule<class r, attr_type>()
auto r = rule<class r_id, attr_type>()
= char_ >> ',' >> int_;

BOOST_TEST((test_attr("test:x,1", "test:" >> r, fv) &&
Expand All @@ -164,7 +164,7 @@ main()
typedef deque<int> attr_type;
attr_type fv;

auto r = rule<class r, attr_type>()
auto r = rule<class r_id, attr_type>()
= int_;

BOOST_TEST((test_attr("test:1", "test:" >> r, fv) &&
Expand Down Expand Up @@ -319,10 +319,10 @@ main()
{
std::vector<std::string> v;

auto e = rule<class e, std::string>()
auto e = rule<class e_id, std::string>()
= *~char_(',');

auto l = rule<class l, std::vector<std::string>>()
auto l = rule<class l_id, std::vector<std::string>>()
= e >> *(',' >> e);

BOOST_TEST(test_attr("abc1,abc2,abc3", l, v));
Expand All @@ -342,10 +342,10 @@ main()

{
std::string s;
auto e = rule<class e, std::string>()
auto e = rule<class e_id, std::string>()
= *~char_(',');

auto l = rule<class l, std::string>()
auto l = rule<class l_id, std::string>()
= e >> *(',' >> e);

BOOST_TEST(test_attr("abc1,abc2,abc3", l, s));
Expand Down Expand Up @@ -428,8 +428,8 @@ main()
{
using Attr = boost::variant<int, float>;
Attr attr;
auto const term = rule<class term, Attr>("term") = int_ | float_;
auto const expr = rule<class expr, Attr>("expr") = term | ('(' > term > ')');
auto const term = rule<class term_id, Attr>("term") = int_ | float_;
auto const expr = rule<class expr_id, Attr>("expr") = term | ('(' > term > ')');
BOOST_TEST((test_attr("(1)", expr, attr, space)));
}

Expand Down

0 comments on commit db8bdf3

Please sign in to comment.