summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang/lib/AST/TemplateBase.cpp6
-rw-r--r--clang/test/SemaTemplate/enum-bool.cpp11
2 files changed, 16 insertions, 1 deletions
diff --git a/clang/lib/AST/TemplateBase.cpp b/clang/lib/AST/TemplateBase.cpp
index d0c938d9243..f8b73cb8f89 100644
--- a/clang/lib/AST/TemplateBase.cpp
+++ b/clang/lib/AST/TemplateBase.cpp
@@ -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/clang/test/SemaTemplate/enum-bool.cpp b/clang/test/SemaTemplate/enum-bool.cpp
new file mode 100644
index 00000000000..31a96e3488e
--- /dev/null
+++ b/clang/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 <E>
+struct S {
+ struct Inner {
+ Inner() {}
+ };
+};
+
+template class S<A>;
OpenPOWER on IntegriCloud