зеркало из https://github.com/microsoft/clang-1.git
Add support for -Wwrite-strings. Patch by Mike M! Fixes PR 4804.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@98541 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Родитель
b6217665c6
Коммит
4b7a834e0f
|
@ -44,6 +44,7 @@ public:
|
|||
|
||||
unsigned PascalStrings : 1; // Allow Pascal strings
|
||||
unsigned WritableStrings : 1; // Allow writable strings
|
||||
unsigned ConstStrings : 1; // Add const qualifier to strings (-Wwrite-strings)
|
||||
unsigned LaxVectorConversions : 1;
|
||||
unsigned AltiVec : 1; // Support AltiVec-style vector initializers.
|
||||
unsigned Exceptions : 1; // Support exception handling.
|
||||
|
@ -129,7 +130,7 @@ public:
|
|||
HexFloats = 0;
|
||||
GC = ObjC1 = ObjC2 = ObjCNonFragileABI = ObjCNonFragileABI2 = 0;
|
||||
C99 = Microsoft = CPlusPlus = CPlusPlus0x = 0;
|
||||
CXXOperatorNames = PascalStrings = WritableStrings = 0;
|
||||
CXXOperatorNames = PascalStrings = WritableStrings = ConstStrings = 0;
|
||||
Exceptions = SjLjExceptions = Freestanding = NoBuiltin = 0;
|
||||
NeXTRuntime = 1;
|
||||
RTTI = 1;
|
||||
|
|
|
@ -197,6 +197,8 @@ def fcolor_diagnostics : Flag<"-fcolor-diagnostics">,
|
|||
HelpText<"Use colors in diagnostics">;
|
||||
def Wno_rewrite_macros : Flag<"-Wno-rewrite-macros">,
|
||||
HelpText<"Silence ObjC rewriting warnings">;
|
||||
def Wwrite_strings : Flag<"-Wwrite-strings">,
|
||||
HelpText<"Add const qualifier to string literals">;
|
||||
def verify : Flag<"-verify">,
|
||||
HelpText<"Verify emitted diagnostics and warnings">;
|
||||
|
||||
|
|
|
@ -474,6 +474,8 @@ static void LangOptsToArgs(const LangOptions &Opts,
|
|||
Res.push_back("-fcatch-undefined-behavior");
|
||||
if (Opts.WritableStrings)
|
||||
Res.push_back("-fwritable-strings");
|
||||
if (Opts.ConstStrings)
|
||||
Res.push_back("-Wwrite-strings");
|
||||
if (!Opts.LaxVectorConversions)
|
||||
Res.push_back("-fno-lax-vector-conversions");
|
||||
if (Opts.AltiVec)
|
||||
|
@ -1162,6 +1164,7 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args,
|
|||
Opts.PascalStrings = Args.hasArg(OPT_fpascal_strings);
|
||||
Opts.Microsoft = Args.hasArg(OPT_fms_extensions);
|
||||
Opts.WritableStrings = Args.hasArg(OPT_fwritable_strings);
|
||||
Opts.ConstStrings = Args.hasArg(OPT_Wwrite_strings);
|
||||
if (Args.hasArg(OPT_fno_lax_vector_conversions))
|
||||
Opts.LaxVectorConversions = 0;
|
||||
if (Args.hasArg(OPT_fno_threadsafe_statics))
|
||||
|
|
|
@ -370,7 +370,7 @@ Sema::ActOnStringLiteral(const Token *StringToks, unsigned NumStringToks) {
|
|||
if (Literal.Pascal) StrTy = Context.UnsignedCharTy;
|
||||
|
||||
// A C++ string literal has a const-qualified element type (C++ 2.13.4p1).
|
||||
if (getLangOptions().CPlusPlus)
|
||||
if (getLangOptions().CPlusPlus || getLangOptions().ConstStrings )
|
||||
StrTy.addConst();
|
||||
|
||||
// Get an array type for the string, according to C99 6.4.5. This includes
|
||||
|
|
|
@ -106,7 +106,7 @@ Expr *Sema::BuildObjCEncodeExpression(SourceLocation AtLoc,
|
|||
// which is an array type.
|
||||
StrTy = Context.CharTy;
|
||||
// A C++ string literal has a const-qualified element type (C++ 2.13.4p1).
|
||||
if (getLangOptions().CPlusPlus)
|
||||
if (getLangOptions().CPlusPlus || getLangOptions().ConstStrings)
|
||||
StrTy.addConst();
|
||||
StrTy = Context.getConstantArrayType(StrTy, llvm::APInt(32, Str.size()+1),
|
||||
ArrayType::Normal, 0);
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
// RUN: %clang_cc1 -verify -fsyntax-only -Wwrite-strings %s
|
||||
|
||||
// PR4804
|
||||
char* x = "foo"; // expected-warning {{initializing 'char const [4]' discards qualifiers, expected 'char *'}}
|
|
@ -0,0 +1,4 @@
|
|||
// RUN: %clang_cc1 -verify -fsyntax-only -Wwrite-strings %s
|
||||
|
||||
// PR4804
|
||||
char* x = "foo"; // expected-warning {{initializing 'char const [4]' discards qualifiers, expected 'char *'}}
|
Загрузка…
Ссылка в новой задаче