Skip to content

Visual Studio: silence warnings about local variables assigned-but-not-used #2460

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 10, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 6 additions & 10 deletions jbmc/src/java_bytecode/java_bytecode_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -460,18 +460,14 @@ bool java_bytecode_parsert::parse()
#define ACC_ANNOTATION 0x2000
#define ACC_ENUM 0x4000

#ifdef _MSC_VER
#define UNUSED
#else
#define UNUSED __attribute__((unused))
#endif
#define UNUSED_u2(x) { const u2 x = read_u2(); (void)x; } (void)0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the (void)0 at the end?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to make sure uses of the macro can (and do) have a semicolon at the end. Without the (void)0 doing so would likely yield a warning (as it would expand to a semicolon after a closing brace).


void java_bytecode_parsert::rClassFile()
{
parse_tree.loading_successful=false;

u4 magic=read_u4();
u2 UNUSED minor_version=read_u2();
UNUSED_u2(minor_version);
u2 major_version=read_u2();

if(magic!=0xCAFEBABE)
Expand Down Expand Up @@ -1180,8 +1176,8 @@ void java_bytecode_parsert::rmethod_attribute(methodt &method)

if(attribute_name=="Code")
{
u2 UNUSED max_stack=read_u2();
u2 UNUSED max_locals=read_u2();
UNUSED_u2(max_stack);
UNUSED_u2(max_locals);

rbytecode(method.instructions);

Expand Down Expand Up @@ -1528,8 +1524,8 @@ void java_bytecode_parsert::relement_value_pair(
{
case 'e':
{
UNUSED u2 type_name_index=read_u2();
UNUSED u2 const_name_index=read_u2();
UNUSED_u2(type_name_index);
UNUSED_u2(const_name_index);
// todo: enum
}
break;
Expand Down