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";
+    }
   }
 }
 


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";
+    }
   }
 }
 
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to