Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 8110728

Browse files
committed
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.
1 parent 2227bb9 commit 8110728

File tree

3 files changed

+6
-17
lines changed

3 files changed

+6
-17
lines changed

src/backend/utils/error/assert.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,8 @@
2121

2222
/*
2323
* ExceptionalCondition - Handles the failure of an Assert()
24-
*
25-
* Note: this can't actually return, but we declare it as returning int
26-
* because the TrapMacro() macro might get wonky otherwise.
2724
*/
28-
int
25+
void
2926
ExceptionalCondition(const char *conditionName,
3027
const char *errorType,
3128
const char *fileName,
@@ -55,6 +52,4 @@ ExceptionalCondition(const char *conditionName,
5552
#endif
5653

5754
abort();
58-
59-
return 0;
6055
}

src/backend/utils/error/elog.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1507,15 +1507,9 @@ pg_re_throw(void)
15071507
errfinish(0);
15081508
}
15091509

1510-
/* We mustn't return... */
1510+
/* Doesn't return ... */
15111511
ExceptionalCondition("pg_re_throw tried to return", "FailedAssertion",
15121512
__FILE__, __LINE__);
1513-
1514-
/*
1515-
* Since ExceptionalCondition isn't declared noreturn because of
1516-
* TrapMacro(), we need this to keep gcc from complaining.
1517-
*/
1518-
abort();
15191513
}
15201514

15211515

src/include/postgres.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -655,14 +655,14 @@ extern PGDLLIMPORT bool assert_enabled;
655655
/*
656656
* TrapMacro is the same as Trap but it's intended for use in macros:
657657
*
658-
* #define foo(x) (AssertMacro(x != 0) && bar(x))
658+
* #define foo(x) (AssertMacro(x != 0), bar(x))
659659
*
660660
* Isn't CPP fun?
661661
*/
662662
#define TrapMacro(condition, errorType) \
663663
((bool) ((! assert_enabled) || ! (condition) || \
664664
(ExceptionalCondition(CppAsString(condition), (errorType), \
665-
__FILE__, __LINE__))))
665+
__FILE__, __LINE__), 0)))
666666

667667
#ifndef USE_ASSERT_CHECKING
668668
#define Assert(condition)
@@ -683,8 +683,8 @@ extern PGDLLIMPORT bool assert_enabled;
683683
Trap(!(condition), "BadState")
684684
#endif /* USE_ASSERT_CHECKING */
685685

686-
extern int ExceptionalCondition(const char *conditionName,
686+
extern void ExceptionalCondition(const char *conditionName,
687687
const char *errorType,
688-
const char *fileName, int lineNumber);
688+
const char *fileName, int lineNumber) __attribute__((noreturn));
689689

690690
#endif /* POSTGRES_H */

0 commit comments

Comments
 (0)