From: | Kyotaro HORIGUCHI <horiguchi(dot)kyotaro(at)lab(dot)ntt(dot)co(dot)jp> |
---|---|
To: | tgl(at)sss(dot)pgh(dot)pa(dot)us |
Cc: | andres(at)anarazel(dot)de, pgsql-hackers(at)postgresql(dot)org |
Subject: | Re: Use an enum for RELKIND_*? |
Date: | 2019-01-28 02:45:20 |
Message-ID: | 20190128.114520.266376949.horiguchi.kyotaro@lab.ntt.co.jp |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
At Thu, 24 Jan 2019 09:37:41 -0500, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote in <15760(dot)1548340661(at)sss(dot)pgh(dot)pa(dot)us>
> Kyotaro HORIGUCHI <horiguchi(dot)kyotaro(at)lab(dot)ntt(dot)co(dot)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
From | Date | Subject | |
---|---|---|---|
Next Message | Amit Kapila | 2019-01-28 02:47:10 | pgsql: Avoid creation of the free space map for small heap relations. |
Previous Message | Kuroda, Hayato | 2019-01-28 01:53:51 | RE: Log a sample of transactions |