Warn about the deprecated string literal -> char* conversion. Fixes PR6428.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@97404 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaExprCXX.cpp b/lib/Sema/SemaExprCXX.cpp
index daa4b5a..23d52ad 100644
--- a/lib/Sema/SemaExprCXX.cpp
+++ b/lib/Sema/SemaExprCXX.cpp
@@ -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:
diff --git a/lib/Sema/SemaOverload.cpp b/lib/Sema/SemaOverload.cpp
index 7846631..ed0d137 100644
--- a/lib/Sema/SemaOverload.cpp
+++ b/lib/Sema/SemaOverload.cpp
@@ -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;
}
diff --git a/lib/Sema/SemaOverload.h b/lib/Sema/SemaOverload.h
index 62b096f..58e416c 100644
--- a/lib/Sema/SemaOverload.h
+++ b/lib/Sema/SemaOverload.h
@@ -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).