[cfe-commits] r65586 - in /cfe/trunk: lib/AST/ASTContext.cpp lib/Sema/SemaInit.cpp test/Sema/wchar_size.c

Chris Lattner sabre at nondot.org
Thu Feb 26 15:36:02 PST 2009


Author: lattner
Date: Thu Feb 26 17:36:02 2009
New Revision: 65586

URL: http://llvm.org/viewvc/llvm-project?rev=65586&view=rev
Log:
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.

Modified:
    cfe/trunk/lib/AST/ASTContext.cpp
    cfe/trunk/lib/Sema/SemaInit.cpp
    cfe/trunk/test/Sema/wchar_size.c

Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=65586&r1=65585&r2=65586&view=diff

==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Thu Feb 26 17:36:02 2009
@@ -1444,8 +1444,6 @@
   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());
 }
 

Modified: cfe/trunk/lib/Sema/SemaInit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=65586&r1=65585&r2=65586&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaInit.cpp (original)
+++ cfe/trunk/lib/Sema/SemaInit.cpp Thu Feb 26 17:36:02 2009
@@ -48,7 +48,7 @@
   // 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;
   

Modified: cfe/trunk/test/Sema/wchar_size.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/wchar_size.c?rev=65586&r1=65585&r2=65586&view=diff

==============================================================================
--- cfe/trunk/test/Sema/wchar_size.c (original)
+++ cfe/trunk/test/Sema/wchar_size.c Thu Feb 26 17:36:02 2009
@@ -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}}
+}





More information about the cfe-commits mailing list