[cfe-commits] r154068 - in /cfe/trunk: 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
David Blaikie
dblaikie at gmail.com
Wed Apr 4 17:16:44 PDT 2012
Author: dblaikie
Date: Wed Apr 4 19:16:44 2012
New Revision: 154068
URL: http://llvm.org/viewvc/llvm-project?rev=154068&view=rev
Log:
Enable warn_impcast_literal_float_to_integer by default.
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;").
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/test/Analysis/array-struct-region.c
cfe/trunk/test/CXX/temp/temp.spec/p5.cpp
cfe/trunk/test/PCH/exprs.h
cfe/trunk/test/Sema/array-init.c
cfe/trunk/test/SemaCXX/overload-call.cpp
cfe/trunk/test/SemaCXX/warn-thread-safety-analysis.cpp
cfe/trunk/test/SemaTemplate/member-template-access-expr.cpp
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=154068&r1=154067&r2=154068&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Wed Apr 4 19:16:44 2012
@@ -1732,7 +1732,7 @@
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;
Modified: cfe/trunk/test/Analysis/array-struct-region.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/array-struct-region.c?rev=154068&r1=154067&r2=154068&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/array-struct-region.c (original)
+++ cfe/trunk/test/Analysis/array-struct-region.c Wed Apr 4 19:16:44 2012
@@ -25,8 +25,8 @@
}
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) {
Modified: cfe/trunk/test/CXX/temp/temp.spec/p5.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/temp/temp.spec/p5.cpp?rev=154068&r1=154067&r2=154068&view=diff
==============================================================================
--- cfe/trunk/test/CXX/temp/temp.spec/p5.cpp (original)
+++ cfe/trunk/test/CXX/temp/temp.spec/p5.cpp Wed Apr 4 19:16:44 2012
@@ -14,9 +14,10 @@
};
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}}
Modified: cfe/trunk/test/PCH/exprs.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/exprs.h?rev=154068&r1=154067&r2=154068&view=diff
==============================================================================
--- cfe/trunk/test/PCH/exprs.h (original)
+++ cfe/trunk/test/PCH/exprs.h Wed Apr 4 19:16:44 2012
@@ -86,7 +86,9 @@
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;
Modified: cfe/trunk/test/Sema/array-init.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/array-init.c?rev=154068&r1=154067&r2=154068&view=diff
==============================================================================
--- cfe/trunk/test/Sema/array-init.c (original)
+++ cfe/trunk/test/Sema/array-init.c Wed Apr 4 19:16:44 2012
@@ -48,7 +48,9 @@
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() {
Modified: cfe/trunk/test/SemaCXX/overload-call.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/overload-call.cpp?rev=154068&r1=154067&r2=154068&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/overload-call.cpp (original)
+++ cfe/trunk/test/SemaCXX/overload-call.cpp Wed Apr 4 19:16:44 2012
@@ -233,7 +233,7 @@
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}}
Modified: cfe/trunk/test/SemaCXX/warn-thread-safety-analysis.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-thread-safety-analysis.cpp?rev=154068&r1=154067&r2=154068&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/warn-thread-safety-analysis.cpp (original)
+++ cfe/trunk/test/SemaCXX/warn-thread-safety-analysis.cpp Wed Apr 4 19:16:44 2012
@@ -1153,7 +1153,7 @@
int Foo::foo()
{
int res;
- w = 5.2;
+ w = 5;
res = a_ + 5;
return res;
}
@@ -1167,7 +1167,7 @@
mu_.Unlock();
if (x > 5) {
mu1.Lock();
- g = 2.3;
+ g = 2;
mu1.Unlock();
}
}
@@ -1185,7 +1185,7 @@
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
Modified: cfe/trunk/test/SemaTemplate/member-template-access-expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/member-template-access-expr.cpp?rev=154068&r1=154067&r2=154068&view=diff
==============================================================================
--- cfe/trunk/test/SemaTemplate/member-template-access-expr.cpp (original)
+++ cfe/trunk/test/SemaTemplate/member-template-access-expr.cpp Wed Apr 4 19:16:44 2012
@@ -60,7 +60,7 @@
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);
More information about the cfe-commits
mailing list