Skip to content

Use bool literal in while loop #2078

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
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
36 changes: 19 additions & 17 deletions src/util/invariant.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ class invariant_failedt: public std::logic_error
// This is *not* recommended as it can result in unpredictable behaviour
// including silently reporting incorrect results.
// This is also useful for checking side-effect freedom.
#define INVARIANT(CONDITION, REASON) do {} while(0)
#define INVARIANT_STRUCTURED(CONDITION, TYPENAME, ...) do {} while(0)
#define INVARIANT(CONDITION, REASON) do {} while(false)
#define INVARIANT_STRUCTURED(CONDITION, TYPENAME, ...) do {} while(false)

#elif defined(CPROVER_INVARIANT_ASSERT)
// Not recommended but provided for backwards compatability
Expand Down Expand Up @@ -202,19 +202,21 @@ inline void invariant_violated_string(
#define __this_function__ __func__
#endif

#define INVARIANT(CONDITION, REASON) \
do /* NOLINT */ \
{ \
if(!(CONDITION)) \
invariant_violated_string(__FILE__, __this_function__, __LINE__, (REASON)); /* NOLINT */ \
} while(0)
#define INVARIANT(CONDITION, REASON) \
do /* NOLINT */ \
{ \
if(!(CONDITION)) \
invariant_violated_string( \
__FILE__, __this_function__, __LINE__, (REASON)); /* NOLINT */ \
} while(false)

#define INVARIANT_STRUCTURED(CONDITION, TYPENAME, ...) \
do /* NOLINT */ \
{ \
if(!(CONDITION)) \
invariant_violated_structured<TYPENAME>(__FILE__, __this_function__, __LINE__, __VA_ARGS__); /* NOLINT */ \
} while(0)
#define INVARIANT_STRUCTURED(CONDITION, TYPENAME, ...) \
do /* NOLINT */ \
{ \
if(!(CONDITION)) \
invariant_violated_structured<TYPENAME>( \
__FILE__, __this_function__, __LINE__, __VA_ARGS__); /* NOLINT */ \
} while(false)

#endif // End CPROVER_DO_NOT_CHECK / CPROVER_ASSERT / ... if block

Expand Down Expand Up @@ -260,8 +262,8 @@ inline void invariant_violated_string(

// The following should not be used in new code and are only intended
// to migrate documentation and "error handling" in older code
#define TODO INVARIANT(0, "Todo")
#define UNIMPLEMENTED INVARIANT(0, "Unimplemented")
#define UNHANDLED_CASE INVARIANT(0, "Unhandled case")
#define TODO INVARIANT(false, "Todo")
#define UNIMPLEMENTED INVARIANT(false, "Unimplemented")
#define UNHANDLED_CASE INVARIANT(false, "Unhandled case")

#endif // CPROVER_UTIL_INVARIANT_H