]> granicus.if.org Git - postgresql/commitdiff
Change return type of ExceptionalCondition to void and mark it noreturn
authorPeter Eisentraut <peter_e@gmx.net>
Sun, 29 Apr 2012 18:07:35 +0000 (21:07 +0300)
committerPeter Eisentraut <peter_e@gmx.net>
Sun, 29 Apr 2012 18:20:14 +0000 (21:20 +0300)
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.

src/backend/utils/error/assert.c
src/backend/utils/error/elog.c
src/include/postgres.h

index ad548239f24be938b1c88403717ae4a8c65c93cc..2908abe852097e02c29e16ba65878b8f56341285 100644 (file)
 
 /*
  * 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,
                                         const char *errorType,
                                         const char *fileName,
@@ -55,6 +52,4 @@ ExceptionalCondition(const char *conditionName,
 #endif
 
        abort();
-
-       return 0;
 }
index 239ac19882d6b020c6eb71a57de1c048d01ebd30..65c28a750807aec39cc6adcc9ad506f16fb31f33 100644 (file)
@@ -1507,15 +1507,9 @@ pg_re_throw(void)
                errfinish(0);
        }
 
-       /* We mustn't return... */
+       /* Doesn't return ... */
        ExceptionalCondition("pg_re_throw tried to return", "FailedAssertion",
                                                 __FILE__, __LINE__);
-
-       /*
-        * Since ExceptionalCondition isn't declared noreturn because of
-        * TrapMacro(), we need this to keep gcc from complaining.
-        */
-       abort();
 }
 
 
index c429f291c2f8b4f8f08734c698c04173d6360f97..94c0218cd1b29d50582f5d497cabed69c11ea768 100644 (file)
@@ -655,14 +655,14 @@ extern PGDLLIMPORT bool assert_enabled;
 /*
  *     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?
  */
 #define TrapMacro(condition, errorType) \
        ((bool) ((! assert_enabled) || ! (condition) || \
                         (ExceptionalCondition(CppAsString(condition), (errorType), \
-                                                                  __FILE__, __LINE__))))
+                                                                  __FILE__, __LINE__), 0)))
 
 #ifndef USE_ASSERT_CHECKING
 #define Assert(condition)
@@ -683,8 +683,8 @@ extern PGDLLIMPORT bool assert_enabled;
                Trap(!(condition), "BadState")
 #endif   /* USE_ASSERT_CHECKING */
 
-extern int ExceptionalCondition(const char *conditionName,
+extern void ExceptionalCondition(const char *conditionName,
                                         const char *errorType,
-                                        const char *fileName, int lineNumber);
+                                        const char *fileName, int lineNumber) __attribute__((noreturn));
 
 #endif   /* POSTGRES_H */