]> granicus.if.org Git - clang/commitdiff
Compute the promoted integer type of fixed-width enums correctly. Found by inspection.
authorEli Friedman <eli.friedman@gmail.com>
Wed, 26 Oct 2011 07:38:19 +0000 (07:38 +0000)
committerEli Friedman <eli.friedman@gmail.com>
Wed, 26 Oct 2011 07:38:19 +0000 (07:38 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@143021 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDecl.cpp
test/CXX/conv/conv.prom/p4.cpp [new file with mode: 0644]

index 2241024ba4dbed6219404087504895a37ebf65da..7ad8fb34b8bd8383c8b358f5d587bcae6272512d 100644 (file)
@@ -9702,7 +9702,11 @@ void Sema::ActOnEnumBody(SourceLocation EnumLoc, SourceLocation LBraceLoc,
     Packed = true;
 
   if (Enum->isFixed()) {
-    BestType = BestPromotionType = Enum->getIntegerType();
+    BestType = Enum->getIntegerType();
+    if (BestType->isPromotableIntegerType())
+      BestPromotionType = Context.getPromotedIntegerType(BestType);
+    else
+      BestPromotionType = BestType;
     // We don't need to set BestWidth, because BestType is going to be the type
     // of the enumerators, but we do anyway because otherwise some compilers
     // warn that it might be used uninitialized.
diff --git a/test/CXX/conv/conv.prom/p4.cpp b/test/CXX/conv/conv.prom/p4.cpp
new file mode 100644 (file)
index 0000000..02a91cd
--- /dev/null
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++0x %s
+
+enum X : short { A, B };
+extern decltype(+A) x;
+extern int x;
+
+enum Y : long { C, D };
+extern decltype(+C) y;
+extern long y;