aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/Sema/SemaExpr.cpp10
-rw-r--r--test/SemaCXX/wchar_t.cpp14
2 files changed, 22 insertions, 2 deletions
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp
index 6438faea0a..77ddbc29dd 100644
--- a/lib/Sema/SemaExpr.cpp
+++ b/lib/Sema/SemaExpr.cpp
@@ -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) {
diff --git a/test/SemaCXX/wchar_t.cpp b/test/SemaCXX/wchar_t.cpp
index 7b3ba880ea..789dbf6438 100644
--- a/test/SemaCXX/wchar_t.cpp
+++ b/test/SemaCXX/wchar_t.cpp
@@ -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);
+}