[PATCH] D125259: [C11] Diagnose unreachable generic selection associations

Arthur Eubanks via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue May 17 09:59:53 PDT 2022


aeubanks added a comment.

  $ 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


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