From: Chris Lattner Date: Thu, 26 Feb 2009 23:36:02 +0000 (+0000) Subject: ok, not as broken as I thought, just confusing. This allows X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=19753cfa6059b237880a91f21ef58f2d8984845f;p=clang ok, not as broken as I thought, just confusing. This allows initialization of wchar_t arrays with wide strings, and generalizes wchar_size.c to work on all targets. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@65586 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp index 2b4bc89aac..f76d320c38 100644 --- a/lib/AST/ASTContext.cpp +++ b/lib/AST/ASTContext.cpp @@ -1444,8 +1444,6 @@ QualType ASTContext::getWCharType() const { if (LangOpts.CPlusPlus) return WCharTy; - // FIXME: In C, shouldn't WCharTy just be a typedef of the target's - // wide-character type? return getFromTargetType(Target.getWCharType()); } diff --git a/lib/Sema/SemaInit.cpp b/lib/Sema/SemaInit.cpp index eeda1d05ca..1f4ab078ef 100644 --- a/lib/Sema/SemaInit.cpp +++ b/lib/Sema/SemaInit.cpp @@ -48,7 +48,7 @@ static Expr *IsStringInit(Expr *Init, QualType DeclType, ASTContext &Context) { // 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.WCharTy, AT->getElementType())) + if (Context.typesAreCompatible(Context.getWCharType(), AT->getElementType())) // Only allow wchar_t x[] = L"foo"; not wchar_t x[] = "foo"; return Init; diff --git a/test/Sema/wchar_size.c b/test/Sema/wchar_size.c index a4041b976d..b7171fec7a 100644 --- a/test/Sema/wchar_size.c +++ b/test/Sema/wchar_size.c @@ -1,3 +1,12 @@ -// RUN: clang %s -fsyntax-only -verify -triple=i686-apple-darwin9 +// RUN: clang %s -fsyntax-only -verify +#include -int check_wchar_size[sizeof(*L"") == 4 ? 1 : -1]; +int check_wchar_size[sizeof(*L"") == sizeof(wchar_t) ? 1 : -1]; + +void foo() { + int t1[] = L"x"; + wchar_t tab[] = L"x"; + + int t2[] = "x"; // expected-error {{initialization}} + char t3[] = L"x"; // expected-error {{initialization}} +}