[cfe-commits] [PATCH] more useful 'duplicate case' diagnostics

Douglas Gregor dgregor at apple.com
Tue May 15 13:09:08 PDT 2012

On May 15, 2012, at 9:05 AM, Terry Long <macmantrl at me.com> wrote:

> Hi all,
> This patch mostly inspired by http://llvm.org/bugs/show_bug.cgi?id=9243 -- poor "duplicate case" diagnostic with enums
> Previously the diagnostic for duplicate case values in switch statements was always something like "duplicate case value '5'" 
> What my patch changes:
> When the duplicate case is exactly the same in textual representation (in source code), the diagnostic will use that exact text in the diagnostic.
> e.g. using MyEnum twice gives the diagnostic "duplicate case value 'MyEnum'"
> If the textual representations differ, the new diagnostic explicitly states they are equal to the same value
> e.g. using MyEnum (equal to 5) and 5, the diagnostic displays "duplicate case value: 'MyEnum' and '5' both equal '5'"
> The patch does the same for any valid expression in a case statement (including macros, const ints, char literals, etc.).

I'm a bit uncomfortable with the textual approach here. Why not analyze the expressions to check whether they are references to named declarations, and use those names in the diagnostic? It won't catch some macro cases, but it's far simpler.

	- Doug

More information about the cfe-commits mailing list