-
Notifications
You must be signed in to change notification settings - Fork 10
Description
With the latest commit I observed the following warnings when compiling code with -Wall -Wextra, which is the default warning level I currently use on my projects.
- Some null-related warnings with
json5pp::value's constructor:
json5pp/json5pp.hpp: In constructor ‘json5pp::value::value(json5pp::value::null_type)’:
json5pp/json5pp.hpp:162:19: warning: unused parameter ‘null’ [-Wunused-parameter]
162 | value(null_type null) noexcept : type(TYPE_NULL) {}
| ~~~~~~~~~~^~~~
json5pp/json5pp.hpp: In member function ‘json5pp::value& json5pp::value::operator=(json5pp::value::null_type)’:
json5pp/json5pp.hpp:594:30: warning: unused parameter ‘null’ [-Wunused-parameter]
594 | value& operator=(null_type null)
| ~~~~~~~~~~^~~~
json5pp::rule::json5()(I use this to read JSON5 fromstd::ifstreamto ajson5pp::value) causes the following notes and warnings:
json5pp/json5pp.hpp:789:65: warning: unused parameter ‘manip’ [-Wunused-parameter]
789 | parser<((F&~C)|S)&M> operator>>(const manipulator_flags<S,C>& manip)
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
json5pp/json5pp.hpp: In member function ‘int json5pp::impl::parser<F>::skip_spaces() [with unsigned int F = 4095]’:
json5pp/json5pp.hpp:873:9: warning: this statement may fall through [-Wimplicit-fallthrough=]
873 | if (has_flag(flags::single_line_comment | flags::multi_line_comment)) {
| ^~
json5pp/json5pp.hpp:908:7: note: here
908 | default:
| ^~~~~~~
json5pp/json5pp.hpp: In member function ‘void json5pp::impl::parser<F>::parse_string(std::string&, int, const char*) [with unsigned int F = 4095]’:
json5pp/json5pp.hpp:1286:11: warning: this statement may fall through [-Wimplicit-fallthrough=]
1286 | if (has_flag(flags::multi_line_string)) {
| ^~
json5pp/json5pp.hpp:1294:9: note: here
1294 | case '\n':
| ^~~~
json5pp/json5pp.hpp:1295:11: warning: this statement may fall through [-Wimplicit-fallthrough=]
1295 | if (has_flag(flags::multi_line_string)) {
| ^~
json5pp/json5pp.hpp:1299:9: note: here
1299 | default:
| ^~~~~~~
json5pp/json5pp.hpp: In member function ‘void json5pp::impl::parser<F>::parse_number(json5pp::value&, int) [with unsigned int F = 4095]’:
json5pp/json5pp.hpp:1173:22: warning: this statement may fall through [-Wimplicit-fallthrough=]
1173 | exp_negative = true;
| ~~~~~~~~~~~~~^~~~~~
json5pp/json5pp.hpp:1175:7: note: here
1175 | case '+':
| ^~~~
This is on gcc/g++ 10.2.0. I haven't noticed any major issues stemmed from those warnings yet, and as I currently have only a few places actually using json5pp::value so I'm currently not getting too many warnings from it. For now I'll suppress the warnings via -isystem to better focus on warnings coming from my own code in case there are any.
EDIT: I noticed some /* no-break */ comments. I'm not certain which compiler/editor respects this comment but g++ actually doesn't. Using // fall through suppressed the implicit fallthrough warnings for g++ according to this. Still I think a portable solution might be needed.
EDIT 2: I just found this method which works to suppress the unused parameter warnings for gcc/g++, as at one time I was dealing with a similar situation. Adding __attribute__((unused)) after the parameter that would not be used in the scope suppressed the warnings in my case. However, like the previous edit, this is probably specific to gcc/g++ and different workarounds might be needed for other compilers.
EDIT 3: Okay... it appeared I used a different method for the unused parameter warnings for the null_type value, by removing the parameter name from the prototype and declaration (leaving only the type).