From 75bc74f305a558354d3fb12f92faf68ec50609be Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Tue, 22 Apr 2014 01:11:06 +0000 Subject: [PATCH] Move the C++11 ExtWarn for converting a string literal to 'char*' out of -Wc++11-compat-deprecated-writable-strings. It's neither a C++11 compatibility warning nor a deprecated feature, it's just ill-formed. In passing, add that warning to -Wdeprecated, where it belongs. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@206833 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/DiagnosticGroups.td | 18 ++++++++++++++---- include/clang/Basic/DiagnosticSemaKinds.td | 2 +- test/SemaCXX/writable-strings-deprecated.cpp | 13 ++++++++++++- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/include/clang/Basic/DiagnosticGroups.td b/include/clang/Basic/DiagnosticGroups.td index f69e738aad..5ab8b97ba7 100644 --- a/include/clang/Basic/DiagnosticGroups.td +++ b/include/clang/Basic/DiagnosticGroups.td @@ -82,11 +82,11 @@ def DeprecatedIncrementBool : DiagGroup<"deprecated-increment-bool">; def DeprecatedRegister : DiagGroup<"deprecated-register">; def DeprecatedWritableStr : DiagGroup<"deprecated-writable-strings", [CXX11CompatDeprecatedWritableStr]>; -// FIXME: Why are DeprecatedImplementations and DeprecatedWritableStr -// not in this group? +// FIXME: Why is DeprecatedImplementations not in this group? def Deprecated : DiagGroup<"deprecated", [DeprecatedDeclarations, DeprecatedIncrementBool, - DeprecatedRegister]>, + DeprecatedRegister, + DeprecatedWritableStr]>, DiagCategory<"Deprecations">; def : DiagGroup<"disabled-optimization">; @@ -422,8 +422,18 @@ def ZeroLengthArray : DiagGroup<"zero-length-array">; def GNUZeroLineDirective : DiagGroup<"gnu-zero-line-directive">; def GNUZeroVariadicMacroArguments : DiagGroup<"gnu-zero-variadic-macro-arguments">; +// This covers both the deprecated case (in C++98) +// and the extension case (in C++11 onwards). +def WritableStrings : DiagGroup<"writable-strings", [DeprecatedWritableStr]>; + // GCC calls -Wdeprecated-writable-strings -Wwrite-strings. -def GCCWriteStrings : DiagGroup<"write-strings" , [DeprecatedWritableStr]>; +// +// Bizarrely, this warning flag enables -fconst-strings in C. This is +// GCC-compatible, but really weird. +// +// FIXME: Should this affect C++11 (where this is an error, +// not just deprecated) or not? +def GCCWriteStrings : DiagGroup<"write-strings" , [WritableStrings]>; def CharSubscript : DiagGroup<"char-subscripts">; def LargeByValueCopy : DiagGroup<"large-by-value-copy">; diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index 03a82ec6e6..67d5e81a93 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -4638,7 +4638,7 @@ def warn_deprecated_string_literal_conversion : Warning< InGroup; def ext_deprecated_string_literal_conversion : ExtWarn< "ISO C++11 does not allow conversion from string literal to %0">, - InGroup, SFINAEFailure; + InGroup, SFINAEFailure; 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">; diff --git a/test/SemaCXX/writable-strings-deprecated.cpp b/test/SemaCXX/writable-strings-deprecated.cpp index b8f605b63d..f925833498 100644 --- a/test/SemaCXX/writable-strings-deprecated.cpp +++ b/test/SemaCXX/writable-strings-deprecated.cpp @@ -1,14 +1,25 @@ // RUN: %clang_cc1 -fsyntax-only -Wno-deprecated-writable-strings -verify %s +// RUN: %clang_cc1 -fsyntax-only -Wno-deprecated -Wdeprecated-increment-bool -verify %s // RUN: %clang_cc1 -fsyntax-only -fwritable-strings -verify %s // RUN: %clang_cc1 -fsyntax-only -Wno-write-strings -verify %s // RUN: %clang_cc1 -fsyntax-only -Werror=c++11-compat -verify %s -DERROR +// RUN: %clang_cc1 -fsyntax-only -Werror=deprecated -Wno-error=deprecated-increment-bool -verify %s -DERROR +// RUN: %clang_cc1 -fsyntax-only -std=c++11 -verify %s +// RUN: %clang_cc1 -fsyntax-only -std=c++11 -verify %s -Wno-deprecated -Wdeprecated-increment-bool +// RUN: %clang_cc1 -fsyntax-only -std=c++11 -verify %s -pedantic-errors -DERROR // rdar://8827606 char *fun(void) { return "foo"; +#if __cplusplus >= 201103L #ifdef ERROR - // expected-error@-2 {{deprecated}} + // expected-error@-3 {{ISO C++11 does not allow conversion from string literal to 'char *'}} +#else + // expected-warning@-5 {{ISO C++11 does not allow conversion from string literal to 'char *'}} +#endif +#elif defined(ERROR) + // expected-error@-8 {{deprecated}} #endif } -- 2.40.0