[PATCH] D79290: Update suffix check and cast non-suffix types

Pratyush Das via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sat May 2 23:18:53 PDT 2020


reikdas updated this revision to Diff 261683.

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D79290/new/

https://reviews.llvm.org/D79290

Files:
  clang/lib/AST/TemplateBase.cpp
  clang/test/Misc/integer-literal-printing.cpp


Index: clang/test/Misc/integer-literal-printing.cpp
===================================================================
--- clang/test/Misc/integer-literal-printing.cpp
+++ clang/test/Misc/integer-literal-printing.cpp
@@ -2,7 +2,7 @@
 
 // PR11179
 template <short T> class Type1 {};
-template <short T> void Function1(Type1<T>& x) {} // expected-note{{candidate function [with T = -42] not viable: expects an l-value for 1st argument}}
+template <short T> void Function1(Type1<T>& x) {} // expected-note{{candidate function [with T = (short)-42] not viable: expects an l-value for 1st argument}}
 
 template <unsigned short T> class Type2 {};
 template <unsigned short T> void Function2(Type2<T>& x) {} // expected-note{{candidate function [with T = 42U] not viable: expects an l-value for 1st argument}}
Index: clang/lib/AST/TemplateBase.cpp
===================================================================
--- clang/lib/AST/TemplateBase.cpp
+++ clang/lib/AST/TemplateBase.cpp
@@ -76,13 +76,18 @@
     Out.write_escaped(StringRef(&Ch, 1), /*UseHexEscapes=*/ true);
     Out << "'";
   } else {
-    Out << Val;
     if (T->isBuiltinType()) {
-      if (Val.isUnsigned())
-        Out << "U";
-      if (Val.getBitWidth() == 64)
-        Out << "LL";
+      if (T->isUnsignedIntegerType() && Val.getBitWidth() == 64)
+        Out << Val << "ULL";
+      else if (T->isSignedIntegerType() && Val.getBitWidth() == 64)
+        Out << Val << "LL";
+      else if (T->isUnsignedIntegerType())
+        Out << Val << "U";
+      else
+        Out << "(" << T->getCanonicalTypeInternal().getAsString(Policy) << ")" << Val;
     }
+    else
+      Out << Val;
   }
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D79290.261683.patch
Type: text/x-patch
Size: 1667 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200503/ad4b61d4/attachment-0001.bin>


More information about the cfe-commits mailing list