Remove assertions that some compiler say are tautological
authorHeikki Linnakangas <[email protected]>
Wed, 20 Mar 2024 07:14:51 +0000 (09:14 +0200)
committerHeikki Linnakangas <[email protected]>
Wed, 20 Mar 2024 07:14:51 +0000 (09:14 +0200)
To avoid the compiler warnings:

    launch_backend.c:211:39: warning: comparison of constant 16 with expression of type 'BackendType' (aka 'enum BackendType') is always true [-Wtautological-constant-out-of-range-compare]
    launch_backend.c:233:39: warning: comparison of constant 16 with expression of type 'BackendType' (aka 'enum BackendType') is always true [-Wtautological-constant-out-of-range-compare]

The point of the assertions was to fail more explicitly if someone
adds a new BackendType to the end of the enum, but forgets to add it
to the child_process_kinds array. It was a pretty weak assertion to
begin with, because it wouldn't catch if you added a new BackendType
in the middle of the enum. So let's just remove it.

Per buildfarm member ayu and a few others, spotted by Tom Lane.

Discussion: https://www.postgresql.org/message-id/4119680.1710913067@sss.pgh.pa.us

src/backend/postmaster/launch_backend.c
src/include/miscadmin.h

index 3b5f73524c0957f615030716c6c06f5870b0621e..cb0c3e2f8ab29817e24b178e17ed5a6089996040 100644 (file)
@@ -208,7 +208,6 @@ child_process_kind child_process_kinds[] = {
 const char *
 PostmasterChildName(BackendType child_type)
 {
-   Assert(child_type >= 0 && child_type < lengthof(child_process_kinds));
    return child_process_kinds[child_type].name;
 }
 
@@ -230,7 +229,6 @@ postmaster_child_launch(BackendType child_type,
 {
    pid_t       pid;
 
-   Assert(child_type >= 0 && child_type < lengthof(child_process_kinds));
    Assert(IsPostmasterEnvironment && !IsUnderPostmaster);
 
 #ifdef EXEC_BACKEND
index f900da61573176a69dd333fe7a877f2c14a01e27..90f9b21b2584df6264cbde0cdde4dd7c3142db8c 100644 (file)
@@ -326,6 +326,9 @@ extern void SwitchBackToLocalLatch(void);
 
 /*
  * MyBackendType indicates what kind of a backend this is.
+ *
+ * If you add entries, please also update the child_process_kinds array in
+ * launch_backend.c.
  */
 typedef enum BackendType
 {