From: Richard Trieu Date: Fri, 9 Jan 2015 00:58:16 +0000 (+0000) Subject: Use APSInt::isSameValue instead of operator== in a place where two APSInt's X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a1712b44df90b7bc23856a48d567bd34a1d43302;p=clang Use APSInt::isSameValue instead of operator== in a place where two APSInt's may have different sizes. Fixes PR22017 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@225488 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AST/TemplateBase.cpp b/lib/AST/TemplateBase.cpp index d0c938d924..f8b73cb8f8 100644 --- a/lib/AST/TemplateBase.cpp +++ b/lib/AST/TemplateBase.cpp @@ -42,7 +42,11 @@ static void printIntegral(const TemplateArgument &TemplArg, if (const EnumType *ET = T->getAs()) { for (const EnumConstantDecl* ECD : ET->getDecl()->enumerators()) { - if (ECD->getInitVal() == Val) { + // In Sema::CheckTemplateArugment, enum template arguments value are + // extended to the size of the integer underlying the enum type. This + // may create a size difference between the enum value and template + // argument value, requiring isSameValue here instead of operator==. + if (llvm::APSInt::isSameValue(ECD->getInitVal(), Val)) { ECD->printQualifiedName(Out, Policy); return; } diff --git a/test/SemaTemplate/enum-bool.cpp b/test/SemaTemplate/enum-bool.cpp new file mode 100644 index 0000000000..31a96e3488 --- /dev/null +++ b/test/SemaTemplate/enum-bool.cpp @@ -0,0 +1,11 @@ +// %RUN: %clang_cc1 -std=c++11 -emit-llvm %s -o %t + +enum E : bool { A }; +template +struct S { + struct Inner { + Inner() {} + }; +}; + +template class S;