]> granicus.if.org Git - clang/commitdiff
fix PR5917, L'x' was getting the wrong type in c++ mode. Per
authorChris Lattner <sabre@nondot.org>
Wed, 30 Dec 2009 21:19:39 +0000 (21:19 +0000)
committerChris Lattner <sabre@nondot.org>
Wed, 30 Dec 2009 21:19:39 +0000 (21:19 +0000)
C++2.13.2p2: "A wide-character literal has type wchar_t"

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@92313 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaExpr.cpp
test/SemaCXX/wchar_t.cpp

index 6438faea0a01a50b0a7e6fa5c62d2e3943dda3b9..77ddbc29dda761cf3a125272ab872b923793f0f5 100644 (file)
@@ -1541,11 +1541,17 @@ Sema::OwningExprResult Sema::ActOnCharacterConstant(const Token &Tok) {
   if (Literal.hadError())
     return ExprError();
 
-  QualType type = getLangOptions().CPlusPlus ? Context.CharTy : Context.IntTy;
+  QualType Ty;
+  if (!getLangOptions().CPlusPlus)
+    Ty = Context.IntTy;   // 'x' and L'x' -> int in C.
+  else if (Literal.isWide())
+    Ty = Context.WCharTy; // L'x' -> wchar_t in C++.
+  else
+    Ty = Context.CharTy;  // 'x' -> char in C++
 
   return Owned(new (Context) CharacterLiteral(Literal.getValue(),
                                               Literal.isWide(),
-                                              type, Tok.getLocation()));
+                                              Ty, Tok.getLocation()));
 }
 
 Action::OwningExprResult Sema::ActOnNumericConstant(const Token &Tok) {
index 7b3ba880ea301e8dbb4e0e9225e9f7904e161e89..789dbf643863fccc31c813cfe166f8bb08fdf254 100644 (file)
@@ -11,3 +11,17 @@ void f(wchar_t p) {
 // PR4502
 wchar_t const c = L'c';
 int a[c == L'c' ? 1 : -1];
+
+
+// PR5917
+template<typename _CharT>
+struct basic_string {
+};
+
+template<typename _CharT>
+basic_string<_CharT> operator+ (const basic_string<_CharT>&, _CharT);
+
+int t(void) {
+  basic_string<wchar_t>() + L'-';
+  return (0);
+}