summaryrefslogtreecommitdiffstats
path: root/clang/test/Sema/switch.c
Commit message (Collapse)AuthorAgeFilesLines
* [c++20] Add deprecation warnings for the expression forms deprecated by P1120R0.Richard Smith2019-12-161-1/+1
| | | | | | | | | | | | | | | | | | | This covers: * usual arithmetic conversions (comparisons, arithmetic, conditionals) between different enumeration types * usual arithmetic conversions between enums and floating-point types * comparisons between two operands of array type The deprecation warnings are on-by-default (in C++20 compilations); it seems likely that these forms will become ill-formed in C++23, so warning on them now by default seems wise. For the first two bullets, off-by-default warnings were also added for all the cases where we didn't already have warnings (covering language modes prior to C++20). These warnings are in subgroups of the existing -Wenum-conversion (except that the first case is not warned on if either enumeration type is anonymous, consistent with our existing -Wenum-conversion warnings).
* [Sema] Add a 'Semantic' parameter to Expr::isKnownToHaveBooleanValueErik Pilkington2019-11-201-0/+11
| | | | | | | | | Some clients of this function want to know about any expression that is known to produce a 0/1 value, and others care about expressions that are semantically boolean. This fixes a -Wswitch-bool regression I introduced in 8bfb353bb33c, pointed out by Chris Hamilton!
* Refactor checking of switch conditions and case values.Richard Smith2018-07-261-1/+1
| | | | | | | | | | | | | | | | | | | Check each case value in turn while parsing it, performing the conversion to the switch type within the context of the expression itself. This will become necessary in order to properly handle cleanups for temporaries created as part of the case label (in an upcoming patch). For now it's just good hygiene. This necessitates moving the checking for the switch condition itself to earlier, so that the destination type is available when checking the case labels. As a nice side-effect, we get slightly improved diagnostic quality and error recovery by separating the case expression checking from the case statement checking and from tracking whether there are discarded case labels. llvm-svn: 338056
* [Sema] Assign new flag -Wenum-compare-switch to switch-related parts of ↵Gabor Horvath2017-08-091-1/+1
| | | | | | | | | | -Wenum-compare Patch by: Reka Nikolett Kovacs Differential Revision: https://reviews.llvm.org/D36526 llvm-svn: 310521
* [Sema] Extend -Wenum-compare to handle mixed enum comparisons in switch ↵Gabor Horvath2017-08-091-0/+1
| | | | | | | | | | statements Patch by: Reka Nikolett Kovacs Differential Revision: https://reviews.llvm.org/D36407 llvm-svn: 310449
* PR11778: Fix the rejects-valid half of this bug. We still produce the sameRichard Smith2014-08-041-1/+11
| | | | | | | poorly-worded warning for a case value that is not a possible value of the switched-on expression. llvm-svn: 214678
* Render anonymous entities as '(anonymous <thing>)' (and lambdas as '(lambda ↵David Blaikie2014-04-021-16/+16
| | | | | | | | | | | | at ... )') For namespaces, this is consistent with mangling and GCC's debug info behavior. For structs, GCC uses <anonymous struct> but we prefer consistency between all anonymous entities but don't want to confuse them with template arguments, etc, so we'll just go with parens in all cases. llvm-svn: 205398
* Allow the warning 'case value not in enumerated type' to be silenced withDmitri Gribenko2013-12-051-0/+26
| | | | | | | | | | the following pattern. If 'case' expression refers to a static const variable of the correct enum type, then we count this as a sufficient declaration of intent by the user, so we silence the warning. llvm-svn: 196546
* Add new -Wunique-enum which will warn on enums which all elements have theRichard Trieu2012-05-301-1/+1
| | | | | | | | | | | | same value and were initialized with literals. Clang will warn on code like this: enum A { FIRST = 1, SECOND = 1 }; llvm-svn: 157666
* Produce more useful 'duplicate case' diagnostics. Fixes PR9243, from Terry Long!Douglas Gregor2012-05-161-1/+30
| | | | llvm-svn: 156904
* For enums with no tag name, display its location in Fariborz Jahanian2012-03-211-16/+33
| | | | | | | the diagnostic instead of displaying ''. // rdar://11082110 llvm-svn: 153219
* Generalize -Wempty-body: warn when statement body is empty (closes: PR11329)Dmitri Gribenko2012-02-141-1/+3
| | | | | | | | | | | | | | * if, switch, range-based for: warn if semicolon is on the same line. * for, while: warn if semicolon is on the same line and either next statement is compound statement or next statement has more indentation. Replacing the semicolon with {} or moving the semicolon to the next line will always silence the warning. Tests from SemaCXX/if-empty-body.cpp merged into SemaCXX/warn-empty-body.cpp. llvm-svn: 150515
* Move -Wcovered-switch-default out of -Wswitch (and -Wall), and make it an ↵Ted Kremenek2012-02-081-1/+1
| | | | | | | | | | | | | opt-in warning. This is a great warning, but it was observed that a ton of real world code violates it all the time for (semi-)legitimate reasons. This warnings is fairly pedantic, which is good, but not for everyone. For example, there is a fair amount of idiomatic code out there that does "default: abort()", and similar idioms. Addresses <rdar://problem/10814651>. llvm-svn: 150055
* In C++11 mode, when an integral constant expression is desired and we have aRichard Smith2012-02-041-2/+5
| | | | | | | | | | | | | | | | | | value of class type, look for a unique conversion operator converting to integral or unscoped enumeration type and use that. Implements [expr.const]p5. Sema::VerifyIntegerConstantExpression now performs the conversion and returns the converted result. Some important callers of Expr::isIntegralConstantExpr have been switched over to using it (including all of those required for C++11 conformance); this switch brings a side-benefit of improved diagnostics and, in several cases, simpler code. However, some language extensions and attributes have not been moved across and will not perform implicit conversions on constant expressions of literal class type where an ICE is required. In passing, fix static_assert to perform a contextual conversion to bool on its argument. llvm-svn: 149776
* Reword/rename -Wswitch-unreachable-default.David Blaikie2012-01-241-1/+1
| | | | | | | | Rewording the diagnostic to be more precise/correct: "default label in switch which covers all enumeration values" and changed the switch to -Wcovered-switch-default llvm-svn: 148783
* Improve -Wswitch-enum diagnostic message.David Blaikie2012-01-241-10/+3
| | | | | | | | | | Changing wording to include the word "explicitly" (as in "enumeration value ... not /explicitly/ handled by switch"), as suggested by Richard Smith. Also, now that the diagnostic text differs between -Wswitch and -Wswitch-enum, I've simplified the test cases a bit. llvm-svn: 148781
* Fix -Wswitch to warn about out of bounds enum cases even when there's a defaultDavid Blaikie2012-01-221-0/+8
| | | | | | | | | For consistency with GCC & reasonable sanity. The FIXME suggests that the original author was perhaps using the default check for some other purpose, not realizing the more obvious limitation/false-negatives it creates, but this doesn't seem to produce any regressions & fixes the included test. llvm-svn: 148649
* Add -Wswitch-enum-redundant-default.David Blaikie2012-01-211-0/+9
| | | | | | | | | | | | | | | | | | | This warning acts as the complement to the main -Wswitch-enum warning (which warns whenever a switch over enum without a default doesn't cover all values of the enum) & has been an an-doc coding convention in LLVM and Clang in my experience. The purpose is to ensure there's never a "dead" default in a switch-over-enum because this would hide future -Wswitch-enum errors. The name warning has a separate flag name so it can be disabled but it's grouped under -Wswitch-enum & is on-by-default because of this. The existing violations of this rule in test cases have had the warning disabled & I've added a specific test for the new behavior (many negative cases already exist in the same test file - and none regressed - so I didn't add more). Reviewed by Ted Kremenek ( http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20120116/051690.html ) llvm-svn: 148640
* C++11 constant expressions: Don't use CheckICE in C++11; instead, determineRichard Smith2011-12-091-2/+2
| | | | | | | | | | | | whether an expression is a (core) constant expression as a side-effect of evaluation. This takes us from accepting far too few expressions as ICEs to accepting slightly too many -- fixes for the remaining cases are coming next. The diagnostics produced when an expression is found to be non-constant are currently quite poor (with generic wording but reasonable source locations), and will be improved in subsequent commits. llvm-svn: 146289
* Tweak the typo-correction implementation to determine correctionsDouglas Gregor2010-10-141-1/+1
| | | | | | | | | | | | | | | | | | | | | solely based on the names it sees, rather than actual declarations it gets. In essence, we determine the set of names that are "close enough" to the typo'd name. Then, we perform name lookup for each of those names, filtering out those that aren't actually visible, and typo-correct from the remaining results. Overall, there isn't much of a change in the behavior of typo correction here. The only test-suite change comes from the fact that we make good on our promise to require that the user type 3 characters for each 1 character corrected. The real intent behind this change is to set the stage for an optimization to typo correction (so that we don't need to deserialize all declarations in a translation unit) and future work in finding missing qualification ("'vector' isn't in scope; did you mean 'std::vector'?). Plus, the code is cleaner this way. llvm-svn: 116511
* turn down the logical bitwise confusion warning to not warn Chris Lattner2010-07-241-4/+2
| | | | | | | | | when the RHS of the ||/&& is ever 0 or 1. This handles a variety of creative idioms for "true" used in C programs and fixes many false positives at the expense of a few false negatives. This fixes rdar://8230351. llvm-svn: 109314
* Add a warning to catch a bug recently caught by code review, like this:Chris Lattner2010-07-131-2/+4
| | | | | | | | | | | t2.c:2:12: warning: use of logical && with constant operand; switch to bitwise & or remove constant [-Wlogical-bitwise-confusion] return x && 4; ^ ~ wording improvement suggestions are welcome. llvm-svn: 108260
* When deciding whether an expression has the boolean nature, don't look throughJohn McCall2010-06-121-0/+11
| | | | | | explicit casts. Fixes PR7359. llvm-svn: 105871
* If a switch condition is constant, don't warn about missing enum cases.John McCall2010-05-181-7/+23
| | | | | | | | If a switch condition is constant, warn if there's no case for it. Constant switch conditions do come up in reasonable template code. llvm-svn: 104010
* Don't warn about case-value conversions from a negative value to aDouglas Gregor2010-03-011-0/+7
| | | | | | | | larger unsigned value, since this is implementation-defined behavior. (We previously suppressed this warning when converting from a signed value to an unsigned value of the same size). llvm-svn: 97430
* Don't diagnose overflow in case statements when the conversion is aDouglas Gregor2010-02-181-0/+14
| | | | | | | signed<->unsigned conversion with the same bit width. Fixes <rdar://problem/7658121>. llvm-svn: 96545
* For -Wswitch-enum warnings, be sure to look through typedefs of enumDouglas Gregor2010-02-171-0/+17
| | | | | | types. Fixes <rdar://problem/7643909>. llvm-svn: 96531
* Warn when cases are missing from a switch on a value of enumerationDouglas Gregor2010-02-081-0/+138
| | | | | | type (-Wswitch), from Michal! llvm-svn: 95592
* Fix the search for visible declarations within a Scope to ensure thatDouglas Gregor2010-01-071-1/+1
| | | | | | | | we look into a Scope that corresponds to a compound statement whose scope was combined with the scope of the function that owns it. This improves typo correction in many common cases. llvm-svn: 92879
* Update tests to use %clang_cc1 instead of 'clang-cc' or 'clang -cc1'.Daniel Dunbar2009-12-151-1/+1
| | | | | | | | | - This is designed to make it obvious that %clang_cc1 is a "test variable" which is substituted. It is '%clang_cc1' instead of '%clang -cc1' because it can be useful to redefine what gets run as 'clang -cc1' (for example, to set a default target). llvm-svn: 91446
* When the condition of a switch() statement is semantically invalid,Douglas Gregor2009-11-251-1/+11
| | | | | | | still parse the body of the switch to try to avoid spurious diagnostics. Fixes PR5606. llvm-svn: 89847
* Implement PR4407 - missing warnings on case value overflow,Chris Lattner2009-10-161-0/+7
| | | | | | patch by Zhanyong Wan! llvm-svn: 84259
* Rename clang to clang-cc.Daniel Dunbar2009-03-241-1/+1
| | | | | | Tests and drivers updated, still need to shuffle dirs. llvm-svn: 67602
* Use VerifyIntegerConstantExpression for case values.Anders Carlsson2008-12-011-4/+4
| | | | llvm-svn: 60317
* Make all the 'redefinition' diagnostics more consistent, and make the Chris Lattner2008-11-231-3/+11
| | | | | | "previously defined here" diagnostics all notes. llvm-svn: 59920
* Case values must be evaluatedAnders Carlsson2008-11-221-0/+10
| | | | llvm-svn: 59884
* Use Expr::Evaluate for case statements. Fixes PR2525Anders Carlsson2008-11-221-0/+22
| | | | llvm-svn: 59881
* rename -parse-ast-print to -ast-printChris Lattner2007-10-111-1/+1
| | | | | | | rename -parse-ast-dump to -ast-dump remove -parse-ast, which is redundant with -fsyntax-only llvm-svn: 42852
* Removed option "-parse-ast-check" from clang driver. This is now implementedTed Kremenek2007-09-261-1/+1
| | | | | | | | | | | | using "-parse-ast -verify". Updated all test cases (using a sed script) that invoked -parse-ast-check to now use -parse-ast -verify. Fixed a bug where using "-verify" instead of "-parse-ast-check" would not correctly create the DiagClient needed to accumulate diagnostics. llvm-svn: 42365
* finish off switch case overlap checking, adding support forChris Lattner2007-08-231-5/+12
| | | | | | verifying case ranges. llvm-svn: 41331
* detect and diagnose empty case ranges:Chris Lattner2007-08-231-0/+2
| | | | | | | | switch.c:16:8: warning: empty case range specified case 100 ... 99: ; // expected-warning {{empty case range}} ^~~~~~~~~~ llvm-svn: 41328
* fix a segfault in cases where there are no cases.Chris Lattner2007-08-231-0/+4
| | | | llvm-svn: 41317
* report duplicate case values. TODO: report duplicate/overlapping ranges.Chris Lattner2007-08-231-1/+2
| | | | llvm-svn: 41315
* start checking case values of switch stmts more closely. Emit overflowChris Lattner2007-08-231-1/+8
| | | | | | warnings when converting case values to the expression type. llvm-svn: 41313
* correctly verify that default and case are in a switchstmt,Chris Lattner2007-07-231-0/+9
this fixes test/Sema/switch.c. llvm-svn: 40438
OpenPOWER on IntegriCloud