[cfe-commits] r97404 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaExprCXX.cpp lib/Sema/SemaOverload.cpp lib/Sema/SemaOverload.h test/CXX/temp/temp.fct.spec/temp.arg.explicit/p3.cpp test/SemaCXX/dcl_init_aggr.cpp test/SemaCXX/overload-call.cpp test/SemaCXX/type-convert-construct.cpp
Douglas Gregor
dgregor at apple.com
Sun Feb 28 10:30:25 PST 2010
Author: dgregor
Date: Sun Feb 28 12:30:25 2010
New Revision: 97404
URL: http://llvm.org/viewvc/llvm-project?rev=97404&view=rev
Log:
Warn about the deprecated string literal -> char* conversion. Fixes PR6428.
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaExprCXX.cpp
cfe/trunk/lib/Sema/SemaOverload.cpp
cfe/trunk/lib/Sema/SemaOverload.h
cfe/trunk/test/CXX/temp/temp.fct.spec/temp.arg.explicit/p3.cpp
cfe/trunk/test/SemaCXX/dcl_init_aggr.cpp
cfe/trunk/test/SemaCXX/overload-call.cpp
cfe/trunk/test/SemaCXX/type-convert-construct.cpp
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=97404&r1=97403&r2=97404&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Sun Feb 28 12:30:25 2010
@@ -1779,7 +1779,8 @@
def err_array_init_not_init_list : Error<
"array initializer must be an initializer "
"list%select{| or string literal}0">;
-
+def warn_deprecated_string_literal_conversion : Warning<
+ "conversion from string literal to %0 is deprecated">;
def err_realimag_invalid_type : Error<"invalid type %0 to %1 operator">;
def err_typecheck_sclass_fscope : Error<
"illegal storage class on file-scoped variable">;
Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=97404&r1=97403&r2=97404&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Sun Feb 28 12:30:25 2010
@@ -1774,6 +1774,11 @@
ImpCastExprToType(From, ToType.getNonReferenceType(),
CastExpr::CK_NoOp,
ToType->isLValueReferenceType());
+
+ if (SCS.DeprecatedStringLiteralToCharPtr)
+ Diag(From->getLocStart(), diag::warn_deprecated_string_literal_conversion)
+ << ToType.getNonReferenceType();
+
break;
default:
Modified: cfe/trunk/lib/Sema/SemaOverload.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=97404&r1=97403&r2=97404&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOverload.cpp Sun Feb 28 12:30:25 2010
@@ -118,7 +118,7 @@
First = ICK_Identity;
Second = ICK_Identity;
Third = ICK_Identity;
- Deprecated = false;
+ DeprecatedStringLiteralToCharPtr = false;
ReferenceBinding = false;
DirectBinding = false;
RRefBinding = false;
@@ -549,7 +549,7 @@
// Standard conversions (C++ [conv])
SCS.setAsIdentityConversion();
- SCS.Deprecated = false;
+ SCS.DeprecatedStringLiteralToCharPtr = false;
SCS.IncompatibleObjC = false;
SCS.setFromType(FromType);
SCS.CopyConstructor = 0;
@@ -592,7 +592,7 @@
if (IsStringLiteralToNonConstPointerConversion(From, ToType)) {
// This conversion is deprecated. (C++ D.4).
- SCS.Deprecated = true;
+ SCS.DeprecatedStringLiteralToCharPtr = true;
// For the purpose of ranking in overload resolution
// (13.3.3.1.1), this conversion is considered an
@@ -1993,7 +1993,7 @@
// the deprecated string literal array to pointer conversion.
switch (Result) {
case ImplicitConversionSequence::Better:
- if (SCS1.Deprecated)
+ if (SCS1.DeprecatedStringLiteralToCharPtr)
Result = ImplicitConversionSequence::Indistinguishable;
break;
@@ -2001,7 +2001,7 @@
break;
case ImplicitConversionSequence::Worse:
- if (SCS2.Deprecated)
+ if (SCS2.DeprecatedStringLiteralToCharPtr)
Result = ImplicitConversionSequence::Indistinguishable;
break;
}
Modified: cfe/trunk/lib/Sema/SemaOverload.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.h?rev=97404&r1=97403&r2=97404&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaOverload.h (original)
+++ cfe/trunk/lib/Sema/SemaOverload.h Sun Feb 28 12:30:25 2010
@@ -117,7 +117,7 @@
/// Deprecated - Whether this the deprecated conversion of a
/// string literal to a pointer to non-const character data
/// (C++ 4.2p2).
- bool Deprecated : 1;
+ bool DeprecatedStringLiteralToCharPtr : 1;
/// IncompatibleObjC - Whether this is an Objective-C conversion
/// that we should warn about (if we actually use it).
Modified: cfe/trunk/test/CXX/temp/temp.fct.spec/temp.arg.explicit/p3.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/temp/temp.fct.spec/temp.arg.explicit/p3.cpp?rev=97404&r1=97403&r2=97404&view=diff
==============================================================================
--- cfe/trunk/test/CXX/temp/temp.fct.spec/temp.arg.explicit/p3.cpp (original)
+++ cfe/trunk/test/CXX/temp/temp.fct.spec/temp.arg.explicit/p3.cpp Sun Feb 28 12:30:25 2010
@@ -3,8 +3,9 @@
template<class X, class Y, class Z> X f(Y,Z); // expected-note {{candidate template ignored: couldn't infer template argument 'X'}}
void g() {
- f<int,char*,double>("aa",3.0);
- f<int,char*>("aa",3.0); // Z is deduced to be double
+ f<int,char*,double>("aa",3.0); // expected-warning{{conversion from string literal to 'char *' is deprecated}}
+ f<int,char*>("aa",3.0); // Z is deduced to be double \
+ // expected-warning{{conversion from string literal to 'char *' is deprecated}}
f<int>("aa",3.0); // Y is deduced to be char*, and
// Z is deduced to be double
f("aa",3.0); // expected-error{{no matching}}
Modified: cfe/trunk/test/SemaCXX/dcl_init_aggr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/dcl_init_aggr.cpp?rev=97404&r1=97403&r2=97404&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/dcl_init_aggr.cpp (original)
+++ cfe/trunk/test/SemaCXX/dcl_init_aggr.cpp Sun Feb 28 12:30:25 2010
@@ -38,7 +38,7 @@
// C++ [dcl.init.aggr]p7
struct TooFew { int a; char* b; int c; };
-TooFew too_few = { 1, "asdf" }; // okay
+TooFew too_few = { 1, "asdf" }; // expected-warning{{conversion from string literal to 'char *' is deprecated}}
struct NoDefaultConstructor { // expected-note 3 {{candidate constructor (the implicit copy constructor)}} \
// expected-note{{declared here}}
Modified: cfe/trunk/test/SemaCXX/overload-call.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/overload-call.cpp?rev=97404&r1=97403&r2=97404&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/overload-call.cpp (original)
+++ cfe/trunk/test/SemaCXX/overload-call.cpp Sun Feb 28 12:30:25 2010
@@ -53,7 +53,7 @@
double* k(bool);
void test_k() {
- int* ip1 = k("foo");
+ int* ip1 = k("foo"); // expected-warning{{conversion from string literal to 'char *' is deprecated}}
double* dp1 = k(L"foo");
}
@@ -61,7 +61,7 @@
double* l(bool);
void test_l() {
- int* ip1 = l(L"foo");
+ int* ip1 = l(L"foo"); // expected-warning{{conversion from string literal to 'wchar_t *' is deprecated}}
double* dp1 = l("foo");
}
@@ -79,7 +79,7 @@
void test_n(E* e) {
char ca[7];
int* ip1 = n(ca);
- int* ip2 = n("foo");
+ int* ip2 = n("foo"); // expected-warning{{conversion from string literal to 'char *' is deprecated}}
float fa[7];
double* dp1 = n(fa);
Modified: cfe/trunk/test/SemaCXX/type-convert-construct.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/type-convert-construct.cpp?rev=97404&r1=97403&r2=97404&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/type-convert-construct.cpp (original)
+++ cfe/trunk/test/SemaCXX/type-convert-construct.cpp Sun Feb 28 12:30:25 2010
@@ -11,7 +11,7 @@
int *p;
bool v6 = T(0) == p;
char *str;
- str = "a string";
+ str = "a string"; // expected-warning{{conversion from string literal to 'char *' is deprecated}}
wchar_t *wstr;
- wstr = L"a wide string";
+ wstr = L"a wide string"; // expected-warning{{conversion from string literal to 'wchar_t *' is deprecated}}
}
More information about the cfe-commits
mailing list