Re: Use an enum for RELKIND_*? - Mailing list pgsql-hackers

From Kyotaro HORIGUCHI
Subject Re: Use an enum for RELKIND_*?
Date
Msg-id 20190128.114520.266376949.horiguchi.kyotaro@lab.ntt.co.jp
Whole thread Raw
In response to Re: Use an enum for RELKIND_*?  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
At Thu, 24 Jan 2019 09:37:41 -0500, Tom Lane <tgl@sss.pgh.pa.us> wrote in <15760.1548340661@sss.pgh.pa.us>
> Kyotaro HORIGUCHI <horiguchi.kyotaro@lab.ntt.co.jp> writes:
> > I might misunderstand something, but my compiler (gcc 7.3.1)
> > won't be quiet about omitted value even with default:.
> > ...
> 
> I would call that a compiler bug, TBH.  The code is 100% correct,
> if you intended to allow the default case to handle some enum
> values, which is perfectly reasonable coding.

Yeah, the code is correct. I had switch-enum in my mind.

We can use #pragma (or _Pragma) to apply an option to a specific
region.

====
#pragma GCC diagnostic push
#pragma GCC diagnostic warning "-Wswitch-enum"
    switch ((type) something)
    {
#pragma GCC diagnostic pop
====

but I don't find a usable form of syntax sugar to wrap this.  The
best I can think of is...


#define STRICT_SWITCH(type, value) { \
    _Pragma ("GCC diagnostic push")\
    _Pragma ("GCC diagnostic warning \"-Wswitch-enum\"")\
    switch((type) (value))

#define END_STRICT_SWITCH() \
    _Pragma ("GCC diagnostic pop") }


(The brace causes syntax error when END_ is omitted, but the
error messages is not so developer friendly...)

====
    STRICT_SWITCH(type, var)
    {
    case xxx:
    ...
    default:
      error(ERROR, (errmsg ("unexpected value %d" (int)var)));
    }
    END_STRICT_SWITCH();
====


> > Isn't it enough that at least one platform correctly warns that?
> 
> No, especially not if it's only a warning.  Many developers would
> not see it initially, and the buildfarm likely wouldn't complain
> either.

I agree that it would be bothersome for people who are working on
such platforms.

regards.

-- 
Kyotaro Horiguchi
NTT Open Source Software Center



pgsql-hackers by date:

Previous
From: "Kuroda, Hayato"
Date:
Subject: RE: Log a sample of transactions
Next
From: Amit Kapila
Date:
Subject: Re: WIP: Avoid creation of the free space map for small tables