[cfe-commits] [PATCH] more useful 'duplicate case' diagnostics
macmantrl at me.com
Tue May 15 09:05:55 PDT 2012
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.).
Concerns with my patch:
1. Multiline case statements, although unusual, will be printed out in the diagnostic exactly as they appear in the source. I'm not sure if this is a real issue. Possible solution would be checking if it spans multiple lines. If so, the diagnostic could be "duplicate case value: both expressions equal 'x'".
case 1 +
2. If a case statement includes a cast, the cast will also be included in the diagnostic. Sometimes this inclusion is helpful, for example in situations where the cast will cause an overflow (such as "(char)256" and "0"). Other times it is irrelevant, such as "(int)7" and "7", where a simple diagnostic of "duplicate case value '7'" makes more sense. I'm also not sure if this is an issue.
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 5620 bytes
Desc: not available
More information about the cfe-commits