From: Richard Trieu Date: Mon, 7 Nov 2011 18:40:31 +0000 (+0000) Subject: Add support for printing integer literals of type short, unsigned short, X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=11cbe2a7fb565678fca456f6bc2d4648ced3adb3;p=clang Add support for printing integer literals of type short, unsigned short, __int128_t and __uint128_t. Short and unsigned short integer literals support is only to work around a crasher as reported in PR11179 and will be removed once Clang no longer builds short integer literals. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@143977 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AST/StmtPrinter.cpp b/lib/AST/StmtPrinter.cpp index 04617bf9ac..807d35875f 100644 --- a/lib/AST/StmtPrinter.cpp +++ b/lib/AST/StmtPrinter.cpp @@ -675,12 +675,19 @@ void StmtPrinter::VisitIntegerLiteral(IntegerLiteral *Node) { // Emit suffixes. Integer literals are always a builtin integer type. switch (Node->getType()->getAs()->getKind()) { default: llvm_unreachable("Unexpected type for integer literal!"); + // FIXME: The Short and UShort cases are to handle cases where a short + // integeral literal is formed during template instantiation. They should + // be removed when template instantiation no longer needs integer literals. + case BuiltinType::Short: + case BuiltinType::UShort: case BuiltinType::Int: break; // no suffix. case BuiltinType::UInt: OS << 'U'; break; case BuiltinType::Long: OS << 'L'; break; case BuiltinType::ULong: OS << "UL"; break; case BuiltinType::LongLong: OS << "LL"; break; case BuiltinType::ULongLong: OS << "ULL"; break; + case BuiltinType::Int128: OS << "i128"; break; + case BuiltinType::UInt128: OS << "Ui128"; break; } } void StmtPrinter::VisitFloatingLiteral(FloatingLiteral *Node) { diff --git a/test/Misc/integer-literal-printing.cpp b/test/Misc/integer-literal-printing.cpp new file mode 100644 index 0000000000..39c7090cae --- /dev/null +++ b/test/Misc/integer-literal-printing.cpp @@ -0,0 +1,21 @@ +// RUN: %clang_cc1 %s -fsyntax-only -verify + +// PR11179 +template class Type1 {}; +template void Function1(Type1& x) {} // expected-note{{candidate function [with T = -42] not viable: no known conversion from 'Type1<-42>' to 'Type1<-42> &' for 1st argument;}} + +template class Type2 {}; +template void Function2(Type2& x) {} // expected-note{{candidate function [with T = 42] not viable: no known conversion from 'Type2<42>' to 'Type2<42> &' for 1st argument;}} + +template <__int128_t T> class Type3 {}; +template <__int128_t T> void Function3(Type3& x) {} // expected-note{{candidate function [with T = -42] not viable: no known conversion from 'Type3<-42>' to 'Type3<-42i128> &' for 1st argument;}} + +template <__uint128_t T> class Type4 {}; +template <__uint128_t T> void Function4(Type4& x) {} // expected-note{{candidate function [with T = 42] not viable: no known conversion from 'Type4<42>' to 'Type4<42Ui128> &' for 1st argument;}} + +void Function() { + Function1(Type1<-42>()); // expected-error{{no matching function for call to 'Function1'}} + Function2(Type2<42>()); // expected-error{{no matching function for call to 'Function2'}} + Function3(Type3<-42>()); // expected-error{{no matching function for call to 'Function3'}} + Function4(Type4<42>()); // expected-error{{no matching function for call to 'Function4'}} +}