r225488 - Use APSInt::isSameValue instead of operator== in a place where two APSInt's

Richard Trieu rtrieu at google.com
Thu Jan 8 16:58:16 PST 2015


Author: rtrieu
Date: Thu Jan  8 18:58:16 2015
New Revision: 225488

URL: http://llvm.org/viewvc/llvm-project?rev=225488&view=rev
Log:
Use APSInt::isSameValue instead of operator== in a place where two APSInt's
may have different sizes.  Fixes PR22017

Added:
    cfe/trunk/test/SemaTemplate/enum-bool.cpp
Modified:
    cfe/trunk/lib/AST/TemplateBase.cpp

Modified: cfe/trunk/lib/AST/TemplateBase.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/TemplateBase.cpp?rev=225488&r1=225487&r2=225488&view=diff
==============================================================================
--- cfe/trunk/lib/AST/TemplateBase.cpp (original)
+++ cfe/trunk/lib/AST/TemplateBase.cpp Thu Jan  8 18:58:16 2015
@@ -42,7 +42,11 @@ static void printIntegral(const Template
 
   if (const EnumType *ET = T->getAs<EnumType>()) {
     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;
       }

Added: cfe/trunk/test/SemaTemplate/enum-bool.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/enum-bool.cpp?rev=225488&view=auto
==============================================================================
--- cfe/trunk/test/SemaTemplate/enum-bool.cpp (added)
+++ cfe/trunk/test/SemaTemplate/enum-bool.cpp Thu Jan  8 18:58:16 2015
@@ -0,0 +1,11 @@
+// %RUN: %clang_cc1 -std=c++11 -emit-llvm %s -o %t
+
+enum E : bool { A };
+template <E>
+struct S {
+  struct Inner {
+    Inner() {}
+  };
+};
+
+template class S<A>;





More information about the cfe-commits mailing list