make trailing ';' mandatory for NS_ASSERT* and NS_FATAL_ERROR macros. fix uses.

Mathieu Lacage 2007-02-21 20:07:39 +01:00
parent 29b2db3a67
commit b95ce71aaf
3 changed files with 29 additions and 16 deletions

View File

@ -22,6 +22,6 @@ int main (int argc, int argv)
NS_ASSERT (a == 0);
NS_ASSERT_MSG (a == 0, "my msg");
NS_ASSERT (a != 0)
NS_ASSERT (a != 0);
NS_ASSERT_MSG (a != 0, "my 2 msg");
}

View File

@ -60,14 +60,19 @@ void AssertBreakpoint (void);
* unverified condition and halts in the ns3::AssertBreakpoint
* function.
*/
#define NS_ASSERT(condition) \
if (!(condition)) \
#define NS_ASSERT(condition) \
do \
{ \
std::cout << "assert failed. file=" << __FILE__ << \
", line=" << __LINE__ << ", cond=\""#condition << \
"\"" << std::endl; \
ns3::AssertBreakpoint (); \
}
if (!(condition)) \
{ \
std::cout << "assert failed. file=" << __FILE__ << \
", line=" << __LINE__ << ", cond=\""#condition << \
"\"" << std::endl; \
ns3::AssertBreakpoint (); \
} \
} \
while (false)
/**
* \ingroup assert
@ -78,12 +83,16 @@ void AssertBreakpoint (void);
* true, the program prints the message to output and
* halts in the ns3::AssertBreakpoint function.
*/
#define NS_ASSERT_MSG(condition, message) \
if (!(condition)) \
{ \
std::cout << message << std::endl; \
ns3::AssertBreakpoint (); \
}
#define NS_ASSERT_MSG(condition, message) \
do \
{ \
if (!(condition)) \
{ \
std::cout << message << std::endl; \
ns3::AssertBreakpoint (); \
} \
} \
while (false)
#else /* NS3_ASSERT_ENABLE */

View File

@ -36,8 +36,12 @@
* builds.
*/
#define NS_FATAL_ERROR(msg) \
std::cout << msg << std::endl; \
ns3::AssertBreakpoint ();
do \
{ \
std::cout << msg << std::endl; \
ns3::AssertBreakpoint (); \
} \
while (false)
#endif /* FATAL_ERROR_H */