[PATCH] D125259: [C11] Diagnose unreachable generic selection associations
Aaron Ballman via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue May 17 10:27:05 PDT 2022
aaron.ballman added a comment.
In D125259#3519822 <https://reviews.llvm.org/D125259#3519822>, @aeubanks wrote:
> $ cat /tmp/a.cc
> typedef struct Test {
> } Test;
>
> void f() {
> const Test constVal;
> _Generic(constVal, const Test : 0);
> }
> $ ./build/rel/bin/clang -fsyntax-only -x c++ /tmp/a.cc -Wall
> /tmp/a.cc:6:28: warning: due to lvalue conversion of the controlling expression, association of type 'const Test' will never be selected because it is qualified [-Wunreachable-code-generic-assoc]
> _Generic(constVal, const Test : 0);
> ^
> /tmp/a.cc:6:35: warning: expression result unused [-Wunused-value]
> _Generic(constVal, const Test : 0);
> ^
> 2 warnings generated.
> $ ./build/rel/bin/clang -fsyntax-only -x c /tmp/a.cc -Wall
> /tmp/a.cc:6:28: warning: due to lvalue conversion of the controlling expression, association of type 'const Test' (aka 'const struct Test') will never be selected because it is qualified [-Wunreachable-code-generic-assoc]
> _Generic(constVal, const Test : 0);
> ^
> /tmp/a.cc:6:12: error: controlling expression type 'Test' (aka 'struct Test') not compatible with any generic association type
> _Generic(constVal, const Test : 0);
> ^~~~~~~~
> 1 warning and 1 error generated.
>
> the C++ case looks wrong, it's warning that `const Test` can't be selected then selects it
Oh wow, good catch! I'll correct this.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D125259/new/
https://reviews.llvm.org/D125259
More information about the cfe-commits
mailing list