]> granicus.if.org Git - clang/commitdiff
Enable warn_impcast_literal_float_to_integer by default.
authorDavid Blaikie <dblaikie@gmail.com>
Thu, 5 Apr 2012 00:16:44 +0000 (00:16 +0000)
committerDavid Blaikie <dblaikie@gmail.com>
Thu, 5 Apr 2012 00:16:44 +0000 (00:16 +0000)
This diagnostic seems to be production ready, it's just an oversight that it
wasn't turned on by default.

The test changes are a bit of a mixed bag. Some tests that seemed like they
clearly didn't need to use this behavior have been modified not to use it.
Others that I couldn't be sure about, I added the necessary expected-warnings
to.

It's possible the diagnostic message could be improved to make it clearer that
this warning can be suppressed by using a value that won't lose precision when
converted to the target type (but can still be a floating point literal, such
as "bool b = 1.0;").

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@154068 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticSemaKinds.td
test/Analysis/array-struct-region.c
test/CXX/temp/temp.spec/p5.cpp
test/PCH/exprs.h
test/Sema/array-init.c
test/SemaCXX/overload-call.cpp
test/SemaCXX/warn-thread-safety-analysis.cpp
test/SemaTemplate/member-template-access-expr.cpp

index f5a72ca99c3893a1e36e26c433953bc07cf4a3f3..3ecb4a7c80b0e8515ae15d6c313f94dd6db90ff7 100644 (file)
@@ -1732,7 +1732,7 @@ def warn_impcast_bitfield_precision_constant : Warning<
 def warn_impcast_literal_float_to_integer : Warning<
   "implicit conversion turns literal floating-point number into integer: "
   "%0 to %1">,
-  InGroup<LiteralConversion>, DefaultIgnore;
+  InGroup<LiteralConversion>;
 def warn_impcast_string_literal_to_bool : Warning<
   "implicit conversion turns string literal into bool: %0 to %1">,
   InGroup<StringConversion>, DefaultIgnore;
index 1284933db09d73c2afe74e344bb9e9209113e0ea..4b085c8d7002ccda9e68b1fceebef710a0cfc1e6 100644 (file)
@@ -25,8 +25,8 @@ int string_literal_init() {
 }
 
 void nested_compound_literals(int rad) {
-  int vec[6][2] = {{0.195, 0.02}, {0.383, 0.067}, {0.55, 0.169},
-                   {0.831, 0.45}, {0.924, 0.617}, {0.98, 0.805}};
+  int vec[6][2] = {{0.195, 0.02}, {0.383, 0.067}, {0.55, 0.169},  // expected-warning 6 {{implicit conversion turns literal floating-point number into integer}}
+                   {0.831, 0.45}, {0.924, 0.617}, {0.98, 0.805}}; // expected-warning 6 {{implicit conversion turns literal floating-point number into integer}}
   int a;
 
   for (a = 0; a < 6; ++a) {
index ba99dd7093a20dd5225b88b7b10591be7a4d3c61..0e69a26b04e2674e15fe6774b3319155d085d024 100644 (file)
@@ -14,9 +14,10 @@ struct X0 {
 };
 
 template<typename T>
-T X0<T>::value = 3.14;
+T X0<T>::value = 3.14; // expected-warning{{implicit conversion turns literal floating-point number into integer}}
 
-template struct X0<int>; // expected-note{{previous explicit instantiation}}
+template struct X0<int>; // expected-note{{previous explicit instantiation}} \
+                            expected-note{{requested here}}
 template struct X0<int>; // expected-error{{duplicate explicit instantiation}}
 
 template void X0<float>::f(float); // expected-note{{previous explicit instantiation}}
index 3495b8b4bbde171e811afd58342981d9bc86ff71..09a50135e40e9425b8ace6fb06bc24a934aac4b1 100644 (file)
@@ -86,7 +86,9 @@ double double_array[3] = { 1.0, 2.0 };
 struct {
   int x;
   float y;
-} designated_inits[3] = { [0].y = 17, [2].x = 12.3, 3.5 };
+} designated_inits[3] = { [0].y = 17,
+                          [2].x = 12.3, // expected-warning {{implicit conversion turns literal floating-point number into integer}}
+                          3.5 };
 
 // TypesCompatibleExpr
 typedef typeof(__builtin_types_compatible_p(float, double)) types_compatible;
index a979fb9e57c3f4cda9a1007cb4b9081f8a7adf82..26c0b2418221d3372a01d48d4cc0c5755213ad92 100644 (file)
@@ -48,7 +48,9 @@ void func() {
   
   extern int blockScopeExtern[3] = { 1, 3, 5 }; // expected-error{{'extern' variable cannot have an initializer}}
   
-  static long x2[3] = { 1.0, "abc" , 5.8 }; // expected-warning{{incompatible pointer to integer conversion initializing 'long' with an expression of type 'char [4]'}}
+  static long x2[3] = { 1.0,
+                        "abc", // expected-warning{{incompatible pointer to integer conversion initializing 'long' with an expression of type 'char [4]'}}
+                         5.8 }; // expected-warning {{implicit conversion turns literal floating-point number into integer}}
 }
 
 void test() {
index 1cfe068a123c36164714a9fce94dc333af7057f9..b5e12148662189684e8eb0f3cc1f582e747e6be4 100644 (file)
@@ -233,7 +233,7 @@ float* intref(const int&);
 
 void intref_test() {
   float* ir1 = intref(5);
-  float* ir2 = intref(5.5);
+  float* ir2 = intref(5.5); // expected-warning{{implicit conversion turns literal floating-point number into integer}}
 }
 
 void derived5(C&); // expected-note{{candidate function not viable: cannot bind base class object of type 'A' to derived class reference 'C &' for 1st argument}}
index 715645c4f0a25fa2c07c79f5424ea7010c11ed25..566e5c1b843bb6af9b516c4fd54a31659e2148f6 100644 (file)
@@ -1153,7 +1153,7 @@ class Foo {
 int Foo::foo()
 {
   int res;
-  w = 5.2;
+  w = 5;
   res = a_ + 5;
   return res;
 }
@@ -1167,7 +1167,7 @@ void Foo::bar()
   mu_.Unlock();
   if (x > 5) {
     mu1.Lock();
-    g = 2.3;
+    g = 2;
     mu1.Unlock();
   }
 }
@@ -1185,7 +1185,7 @@ void main()
   f2->bar(); // expected-warning {{cannot call function 'bar' while mutex 'mu_' is locked}}
   f2->mu_.Unlock();
   mu2.Lock();
-  w = 2.5;
+  w = 2;
   mu2.Unlock();
 }
 } // end namespace thread_annot_lock_13
index dbd27c456c5105be1fa121a5cfb821109d4eab1d..c95b57d4b4fddedd66e17d9f63c75d09125d4524 100644 (file)
@@ -60,7 +60,7 @@ struct X1 {
 
 void test_X1(X1 x1) {
   float *fp1 = x1.f1<>(17);
-  float *fp2 = x1.f1<int>(3.14);
+  float *fp2 = x1.f1<int>(3.14); // expected-warning {{implicit conversion turns literal floating-point number into integer}}
   int *ip1 = x1.f1(17);
   float *ip2 = x1.f1(3.14);