[PATCH] D34912: Handle cases where the value is too large to fit into the underlying type.

Vassil Vassilev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 4 07:13:23 PDT 2017


v.g.vassilev updated this revision to Diff 105172.
v.g.vassilev added a comment.

Add test case.


https://reviews.llvm.org/D34912

Files:
  lib/AST/TemplateBase.cpp
  test/SemaTemplate/temp_arg_nontype.cpp


Index: test/SemaTemplate/temp_arg_nontype.cpp
===================================================================
--- test/SemaTemplate/temp_arg_nontype.cpp
+++ test/SemaTemplate/temp_arg_nontype.cpp
@@ -463,3 +463,8 @@
   T foo = "foo";
   void g() { A<&foo>().f(); }
 }
+
+namespace template_ull {
+  template <unsigned long long> struct S{}; // expected-note-re {{conversion from 'int' to 'const template_ull::S<{{[0-9]+}}ull> &'}}
+  S<(unsigned long long)-1> s = 42; // expected-error {{no viable conversion from 'int' to 'S<(unsigned long long)-1>'}}
+}
Index: lib/AST/TemplateBase.cpp
===================================================================
--- lib/AST/TemplateBase.cpp
+++ lib/AST/TemplateBase.cpp
@@ -62,6 +62,12 @@
     Out << "'";
   } else {
     Out << Val;
+    // Handle cases where the value is too large to fit into the underlying type
+    // i.e. where the unsignedness matters.
+    if (const BuiltinType *BT = T->getAs<BuiltinType>()) {
+      if (Val.isUnsigned() && Val.getBitWidth() == 64 && Val.isNegative())
+        Out << "ull";
+    }
   }
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D34912.105172.patch
Type: text/x-patch
Size: 1086 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170704/1d99cc2e/attachment-0001.bin>


More information about the cfe-commits mailing list