]> granicus.if.org Git - clang/commitdiff
ok, not as broken as I thought, just confusing. This allows
authorChris Lattner <sabre@nondot.org>
Thu, 26 Feb 2009 23:36:02 +0000 (23:36 +0000)
committerChris Lattner <sabre@nondot.org>
Thu, 26 Feb 2009 23:36:02 +0000 (23:36 +0000)
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

lib/AST/ASTContext.cpp
lib/Sema/SemaInit.cpp
test/Sema/wchar_size.c

index 2b4bc89aacef7eca8638b12bcbaa27c25f4f3da2..f76d320c3864965ce7270e1a20bf05ec77213844 100644 (file)
@@ -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());
 }
 
index eeda1d05ca3940e130ba2e782bfed64b8acf931f..1f4ab078efa777a6170866f0a3ffd26a1a8cc2b0 100644 (file)
@@ -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;
   
index a4041b976da99af6430f551103b17e43fbf71248..b7171fec7a551451c53693eea4b16e2f7c70c727 100644 (file)
@@ -1,3 +1,12 @@
-// RUN: clang %s -fsyntax-only -verify -triple=i686-apple-darwin9
+// RUN: clang %s -fsyntax-only -verify 
+#include <wchar.h>
 
-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}}
+}