Diagnose unreachable generic selection associations
authorAaron Ballman <aaron@aaronballman.com>
Tue, 10 May 2022 15:14:24 +0000 (11:14 -0400)
committerAaron Ballman <aaron@aaronballman.com>
Tue, 10 May 2022 15:15:56 +0000 (11:15 -0400)
commitca75ac5f04f269def97e6844c2f5c9596b29c84c
tree0152bc16c5c206532413cfce68b02ca913e888c0
parent71728360ada3e0f6c21d4c09d33424f6150afcc9
Diagnose unreachable generic selection associations

The controlling expression of a _Generic selection expression undergoes
lvalue conversion, array conversion, and function conversion before
picking the association. This means that array types, function types,
and qualified types are all unreachable code if they're used as an
association. I've been caught by this twice in the past few months and
I figure that if a WG14 member can't seem to remember this rule, users
are also likely to struggle with it. So this adds an on-by-default
unreachable code diagnostic for generic selection expression
associations.

Note, we don't have to worry about function types as those are already
a constraint violation which generates an error.

Differential Revision: https://reviews.llvm.org/D125259
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticGroups.td
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaExpr.cpp
clang/test/Sema/generic-selection.c