From: Chris Lattner Date: Wed, 30 Dec 2009 21:19:39 +0000 (+0000) Subject: fix PR5917, L'x' was getting the wrong type in c++ mode. Per X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e8337dff778f6386f0a2a08f5def71a8dd44f2c8;p=clang 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" git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@92313 91177308-0d34-0410-b5e6-96231b3b80d8 --- 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 +struct basic_string { +}; + +template +basic_string<_CharT> operator+ (const basic_string<_CharT>&, _CharT); + +int t(void) { + basic_string() + L'-'; + return (0); +}