Skip to content

Commit e84c019

Browse files
committed
Fix maintenance hazards caused by ill-considered use of default: cases.
Remove default cases from assorted switches over ObjectClass and some related enum types, so that we'll get compiler warnings when someone adds a new enum value without accounting for it in all these places. In passing, re-order some switch cases as needed to match the declaration of enum ObjectClass. OK, that's just neatnik-ism, but I dislike code that looks like it was assembled with the help of a dartboard. Discussion: https://postgr.es/m/20170512221010.nglatgt5azzdxjlj@alvherre.pgsql
1 parent b5b0db1 commit e84c019

File tree

4 files changed

+259
-180
lines changed

4 files changed

+259
-180
lines changed

src/backend/catalog/dependency.c

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1204,6 +1204,10 @@ doDeletion(const ObjectAddress *object, int flags)
12041204
RemoveSchemaById(object->objectId);
12051205
break;
12061206

1207+
case OCLASS_STATISTIC_EXT:
1208+
RemoveStatisticsById(object->objectId);
1209+
break;
1210+
12071211
case OCLASS_TSPARSER:
12081212
RemoveTSParserById(object->objectId);
12091213
break;
@@ -1265,13 +1269,20 @@ doDeletion(const ObjectAddress *object, int flags)
12651269
DropTransformById(object->objectId);
12661270
break;
12671271

1268-
case OCLASS_STATISTIC_EXT:
1269-
RemoveStatisticsById(object->objectId);
1272+
/*
1273+
* These global object types are not supported here.
1274+
*/
1275+
case OCLASS_ROLE:
1276+
case OCLASS_DATABASE:
1277+
case OCLASS_TBLSPACE:
1278+
case OCLASS_SUBSCRIPTION:
1279+
elog(ERROR, "global objects cannot be deleted by doDeletion");
12701280
break;
12711281

1272-
default:
1273-
elog(ERROR, "unrecognized object class: %u",
1274-
object->classId);
1282+
/*
1283+
* There's intentionally no default: case here; we want the
1284+
* compiler to warn if a new OCLASS hasn't been handled above.
1285+
*/
12751286
}
12761287
}
12771288

0 commit comments

Comments
 (0)