diff options
author | Eli Friedman <eli.friedman@gmail.com> | 2009-05-31 10:54:53 +0000 |
---|---|---|
committer | Eli Friedman <eli.friedman@gmail.com> | 2009-05-31 10:54:53 +0000 |
commit | bb6415c69fc6440c337970e39749d4d482d9de42 (patch) | |
tree | c50493a07c3b6fb1c52d81c18e0f0052892c685a /lib/Sema/SemaInit.cpp | |
parent | c8ab2563ac8f7dcc4fdc518b5cc7015ecbb2f003 (diff) |
Fix for PR4285: allow intializing a const wchar_t array with a wide
string.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@72663 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaInit.cpp')
-rw-r--r-- | lib/Sema/SemaInit.cpp | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/lib/Sema/SemaInit.cpp b/lib/Sema/SemaInit.cpp index 4976bd466f..4e0eb1d431 100644 --- a/lib/Sema/SemaInit.cpp +++ b/lib/Sema/SemaInit.cpp @@ -44,17 +44,19 @@ static Expr *IsStringInit(Expr *Init, QualType DeclType, ASTContext &Context) { // Otherwise we can only handle string literals. StringLiteral *SL = dyn_cast<StringLiteral>(Init); if (SL == 0) return 0; - + + QualType ElemTy = Context.getCanonicalType(AT->getElementType()); // char array can be initialized with a narrow string. // Only allow char x[] = "foo"; not char x[] = L"foo"; if (!SL->isWide()) - return AT->getElementType()->isCharType() ? Init : 0; - - // wchar_t array can be initialized with a wide string: C99 6.7.8p15: - // "An array with element type compatible with wchar_t may be initialized by a - // wide string literal, optionally enclosed in braces." - if (Context.typesAreCompatible(Context.getWCharType(), AT->getElementType())) - // Only allow wchar_t x[] = L"foo"; not wchar_t x[] = "foo"; + return ElemTy->isCharType() ? Init : 0; + + // wchar_t array can be initialized with a wide string: C99 6.7.8p15 (with + // correction from DR343): "An array with element type compatible with a + // qualified or unqualified version of wchar_t may be initialized by a wide + // string literal, optionally enclosed in braces." + if (Context.typesAreCompatible(Context.getWCharType(), + ElemTy.getUnqualifiedType())) return Init; return 0; |