On Tue, May 10, 2022 at 08:58:46AM -0400, Jason Merrill wrote: > On 5/7/22 18:26, Marek Polacek wrote: > > Corrected version that avoids an uninitialized warning: > > > > This PR complains that we emit the "enumeration value not handled in > > switch" warning even though the enumerator was marked with the > > [[maybe_unused]] attribute. > > > > The first snag was that I couldn't just check TREE_USED, because > > the enumerator could have been used earlier in the function, which > > doesn't play well with the c_do_switch_warnings warning. Instead, > > I had to check the attributes on the CONST_DECL directly, which led > > to the second, and worse, snag: in C we don't have direct access to > > the CONST_DECL for the enumerator. > > I wonder if you want to change that instead of working around it?
I wouldn't mind looking into that; I've hit this discrepancy numerous times throughout the years and it'd be good to unify it so that the c-common code doesn't need to hack around it. Let's see how far I'll get... > > + const bool unused_p = (lookup_attribute ("unused", attrs) > > + || lookup_attribute ("maybe_unused", attrs)); > > Why is this calculation... > > > node = splay_tree_lookup (cases, (splay_tree_key) value); > > if (node) > > { > > @@ -1769,6 +1784,10 @@ c_do_switch_warnings (splay_tree cases, location_t > > switch_location, > > /* We've now determined that this enumerated literal isn't > > handled by the case labels of the switch statement. */ > > + /* Don't warn if the enumerator was marked as unused. */ > > + if (unused_p) > > + continue; > > ...separate from this test? Ah, that must be a remnant from a previous version of the patch. No reason for the separation anymore. Thanks, Marek