]> granicus.if.org Git - clang/commitdiff
Use APSInt::isSameValue instead of operator== in a place where two APSInt's
authorRichard Trieu <rtrieu@google.com>
Fri, 9 Jan 2015 00:58:16 +0000 (00:58 +0000)
committerRichard Trieu <rtrieu@google.com>
Fri, 9 Jan 2015 00:58:16 +0000 (00:58 +0000)
may have different sizes.  Fixes PR22017

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@225488 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/TemplateBase.cpp
test/SemaTemplate/enum-bool.cpp [new file with mode: 0644]

index d0c938d92435108ea988f1e7cfdc9b13958c971d..f8b73cb8f89a9c2a4e95ade6ae0bfe17b9c894f1 100644 (file)
@@ -42,7 +42,11 @@ static void printIntegral(const TemplateArgument &TemplArg,
 
   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;
       }
diff --git a/test/SemaTemplate/enum-bool.cpp b/test/SemaTemplate/enum-bool.cpp
new file mode 100644 (file)
index 0000000..31a96e3
--- /dev/null
@@ -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>;