[cfe-commits] r92313 - in /cfe/trunk: lib/Sema/SemaExpr.cpp test/SemaCXX/wchar_t.cpp
Chris Lattner
sabre at nondot.org
Wed Dec 30 13:19:39 PST 2009
Author: lattner
Date: Wed Dec 30 15:19:39 2009
New Revision: 92313
URL: http://llvm.org/viewvc/llvm-project?rev=92313&view=rev
Log:
fix PR5917, L'x' was getting the wrong type in c++ mode. Per
C++2.13.2p2: "A wide-character literal has type wchar_t"
Modified:
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/test/SemaCXX/wchar_t.cpp
Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=92313&r1=92312&r2=92313&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Wed Dec 30 15:19:39 2009
@@ -1541,11 +1541,17 @@
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) {
Modified: cfe/trunk/test/SemaCXX/wchar_t.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/wchar_t.cpp?rev=92313&r1=92312&r2=92313&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/wchar_t.cpp (original)
+++ cfe/trunk/test/SemaCXX/wchar_t.cpp Wed Dec 30 15:19:39 2009
@@ -11,3 +11,17 @@
// 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);
+}
More information about the cfe-commits
mailing list