Re: enable fallthrough warnings on clang - Mailing list pgsql-hackers

From Peter Eisentraut
Subject Re: enable fallthrough warnings on clang
Date
Msg-id 94a2bc01-e1bf-4e07-ba58-18dc5aacc0e9@eisentraut.org
Whole thread Raw
In response to Re: enable fallthrough warnings on clang  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: enable fallthrough warnings on clang
List pgsql-hackers
On 06.04.26 23:31, Tom Lane wrote:
> Peter Eisentraut <peter@eisentraut.org> writes:
>> I have committed this patch set.  I also added a test into the C++ module.
> 
> BF member ayu is failing said test:
> 
> 
> ccache clang++-4.0 -std=gnu++11 -Wall -Wpointer-arith -Werror=vla -Wmissing-format-attribute -Wimplicit-fallthrough
-Wformat-security-fno-strict-aliasing -fwrapv -g -O2 -fPIC -fvisibility=hidden -fvisibility-inlines-hidden -I. -I.
-I../../../../src/include-D_GNU_SOURCE  -I/usr/include/libxml2     -c -o test_cplusplusext.o test_cplusplusext.cpp
 
> test_cplusplusext.cpp:66:3: warning: unannotated fall-through between switch labels [-Wimplicit-fallthrough]
>                  case 2:
>                  ^
> test_cplusplusext.cpp:66:3: note: insert '[[clang::fallthrough]];' to silence this warning
>                  case 2:
>                  ^
>                  [[clang::fallthrough]];
> test_cplusplusext.cpp:66:3: note: insert 'break;' to avoid fall-through
>                  case 2:
>                  ^
>                  break;
> 1 warning generated.
> 
> 
> I don't know if it's worth catering to this extremely old
> clang version ...

It appears that we could satisfy clang 6 through 9 with something like

#elif defined(__clang__)
#define pg_fallthrough [[clang::fallthrough]]
#else

Clang >=10 support the existing #elif __has_attribute(fallthrough) branch.

But AFAICT, clang 5 and older are completely broken in this regard, 
because they react to the presence of [[clang::fallthrough]] with a 
syntax error ("error: expected expression").  Not even clang's own 
example code[0] works.

[0]: 
https://releases.llvm.org/5.0.2/tools/clang/docs/AttributeReference.html#fallthrough-clang-fallthrough

Also, this only appears to affect C++.  In C mode, before clang 10, the 
warning option -Wimplicit-fallthrough doesn't appear to do anything.




pgsql-hackers by date:

Previous
From: Xuneng Zhou
Date:
Subject: Re: Implement waiting for wal lsn replay: reloaded
Next
From: SATYANARAYANA NARLAPURAM
Date:
Subject: Re: SQL:2011 Application Time Update & Delete