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()) { + 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 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>'}} +}