summaryrefslogtreecommitdiffstats
path: root/clang/test/SemaCXX/warn-literal-conversion.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Fix float->int conversion warnings when near barriers.Erich Keane2018-05-081-0/+4
| | | | | | | | | | | | As Eli brought up here: https://reviews.llvm.org/D46535 I'd previously messed up this fix by missing conversions that are just slightly outside the range. This patch fixes this by no longer ignoring the return value of convertToInteger. Additionally, one of the error messages wasn't very sensical (mentioning out of range value, when it really was not), so it was cleaned up as well. llvm-svn: 331812
* Correct warning on Float->Integer conversions.Erich Keane2018-05-071-0/+7
| | | | | | | | | | | | | | | | | | As identified and briefly discussed here: https://bugs.llvm.org/show_bug.cgi?id=37305 Converting a floating point number to an integer type when the integral part is out of the range of the integer type is undefined behavior in C. Additionally, CodeGen emits an undef in this situation. HOWEVER, we've been giving a warning that says that the value is changed. This patch corrects the warning to list that it is actually undefined behavior. Differential Revision: https://reviews.llvm.org/D46535 llvm-svn: 331673
* Revert the bool portion of r267054Richard Trieu2016-04-221-0/+11
| | | | | | | Remove the floating point to bool conversion warnings. Some of these conversions will be caught by -Wliteral-conversion and -Wfloat-conversion llvm-svn: 267234
* Split interesting warnings off from -Wfloat-conversionRichard Trieu2016-04-211-12/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Restructure the implict floating point to integer conversions so that interesting sub-groups are under different flags. Breakdown of warnings: No warning: Exact conversions from floating point to integer: int x = 10.0; int x = 1e10; -Wliteral-conversion - Floating point literal to integer with rounding: int x = 5.5; int x = -3.4; -Wfloat-conversion - All conversions not covered by the above two: int x = GetFloat(); int x = 5.5 + 3.5; -Wfloat-zero-conversion - The expression converted has a non-zero floating point value that gets converted to a zero integer value, excluded the cases falling under -Wliteral-conversion. Subset of -Wfloat-conversion. int x = 1.0 / 2.0; -Wfloat-overflow-conversion - The floating point value is outside the range of the integer type, exluding cases from -Wliteral conversion. Subset of -Wfloat-conversion. char x = 500; char x = -1000; -Wfloat-bool-conversion - Any conversion of a floating point type to bool. Subset of -Wfloat-conversion. if (GetFloat()) {} bool x = 5.0; -Wfloat-bool-constant-conversion - Conversion of a compile time evaluatable floating point value to bool. Subset of -Wfloat-bool-conversion. bool x = 1.0; bool x = 4.0 / 20.0; Also add EvaluateAsFloat to Sema, which is similar to EvaluateAsInt, but for floating point values. llvm-svn: 267054
* When performing an implicit from float to bool, the floating point value ↵Aaron Ballman2015-12-301-0/+11
| | | | | | | | must be *exactly* zero in order for the conversion to result in 0. This does not involve a conversion through an integer value, and so truncation of the value is not performed. This patch address PR25876. llvm-svn: 256643
* Improve some of the conversion warnings to fire on conversion to bool.David Blaikie2012-05-151-14/+14
| | | | | | | | | | | Moves the bool bail-out down a little in SemaChecking - so now -Wnull-conversion and -Wliteral-conversion can fire when the target type is bool. Also improve the wording/details in the -Wliteral-conversion warning to match the -Wconstant-conversion. llvm-svn: 156826
* Only warn in -Wliteral-conversion if the conversion loses informationMatt Beaumont-Gay2011-10-141-10/+5
| | | | llvm-svn: 141955
* Move string literal to bool conversion into its own warning flag ↵Richard Trieu2011-09-261-16/+0
| | | | | | -Wstring-conversion. llvm-svn: 140574
* Add a new warning to -Wliteral-conversion to catch cases where a string literalRichard Trieu2011-09-231-0/+16
| | | | | | | | | | | | | | is cast to a boolean. An exception has been made for string literals in logical expressions to allow the common case of use in assert statements. bool x; x = "hi"; // Warn here void foo(bool x); foo("hi"); // Warn here assert(0 && "error"); assert("error); // Warn here llvm-svn: 140405
* Extend -Wliteral-conversion to catch "int i = -1.234"Matt Beaumont-Gay2011-09-081-2/+1
| | | | llvm-svn: 139326
* Enhance the diagnostic for literal float -> int conversions to suggestChandler Carruth2011-04-101-5/+10
| | | | | | | | | | | | rewriting the literal when the value is integral. It is not uncommon to see code written as: const int kBigNumber = 42e5; Without any real awareness that this is no longer an ICE. The note helps automate and ease the process of fixing code that violates the warning. llvm-svn: 129243
* Implement a sub-group of -Wconversion: -Wliteral-conversion. ThisChandler Carruth2011-02-171-0/+41
specifically targets literals which are implicitly converted, a those are more often unintended and trivial to fix. This can be especially helpful for diagnosing what makes 'const int x = 1e6' not an ICE. Original patch authored by Jim Meehan with contributions from other Googlers and a few cleanups from myself. llvm-svn: 125745
OpenPOWER on IntegriCloud