Change return type of ExceptionalCondition to void and mark it noreturn

In ancient times, it was thought that this wouldn't work because of
TrapMacro/AssertMacro, but changing those to use a comma operator
appears to work without compiler warnings.
This commit is contained in:
Peter Eisentraut 2012-04-29 21:07:35 +03:00
parent 2227bb9c94
commit 81107282a5
3 changed files with 6 additions and 17 deletions

View File

@ -21,11 +21,8 @@
/* /*
* ExceptionalCondition - Handles the failure of an Assert() * ExceptionalCondition - Handles the failure of an Assert()
*
* Note: this can't actually return, but we declare it as returning int
* because the TrapMacro() macro might get wonky otherwise.
*/ */
int void
ExceptionalCondition(const char *conditionName, ExceptionalCondition(const char *conditionName,
const char *errorType, const char *errorType,
const char *fileName, const char *fileName,
@ -55,6 +52,4 @@ ExceptionalCondition(const char *conditionName,
#endif #endif
abort(); abort();
return 0;
} }

View File

@ -1507,15 +1507,9 @@ pg_re_throw(void)
errfinish(0); errfinish(0);
} }
/* We mustn't return... */ /* Doesn't return ... */
ExceptionalCondition("pg_re_throw tried to return", "FailedAssertion", ExceptionalCondition("pg_re_throw tried to return", "FailedAssertion",
__FILE__, __LINE__); __FILE__, __LINE__);
/*
* Since ExceptionalCondition isn't declared noreturn because of
* TrapMacro(), we need this to keep gcc from complaining.
*/
abort();
} }

View File

@ -655,14 +655,14 @@ extern PGDLLIMPORT bool assert_enabled;
/* /*
* TrapMacro is the same as Trap but it's intended for use in macros: * TrapMacro is the same as Trap but it's intended for use in macros:
* *
* #define foo(x) (AssertMacro(x != 0) && bar(x)) * #define foo(x) (AssertMacro(x != 0), bar(x))
* *
* Isn't CPP fun? * Isn't CPP fun?
*/ */
#define TrapMacro(condition, errorType) \ #define TrapMacro(condition, errorType) \
((bool) ((! assert_enabled) || ! (condition) || \ ((bool) ((! assert_enabled) || ! (condition) || \
(ExceptionalCondition(CppAsString(condition), (errorType), \ (ExceptionalCondition(CppAsString(condition), (errorType), \
__FILE__, __LINE__)))) __FILE__, __LINE__), 0)))
#ifndef USE_ASSERT_CHECKING #ifndef USE_ASSERT_CHECKING
#define Assert(condition) #define Assert(condition)
@ -683,8 +683,8 @@ extern PGDLLIMPORT bool assert_enabled;
Trap(!(condition), "BadState") Trap(!(condition), "BadState")
#endif /* USE_ASSERT_CHECKING */ #endif /* USE_ASSERT_CHECKING */
extern int ExceptionalCondition(const char *conditionName, extern void ExceptionalCondition(const char *conditionName,
const char *errorType, const char *errorType,
const char *fileName, int lineNumber); const char *fileName, int lineNumber) __attribute__((noreturn));
#endif /* POSTGRES_H */ #endif /* POSTGRES_H */