[cfe-commits] r143021 - in /cfe/trunk: lib/Sema/SemaDecl.cpp test/CXX/conv/conv.prom/p4.cpp

Eli Friedman eli.friedman at gmail.com
Wed Oct 26 00:38:19 PDT 2011


Author: efriedma
Date: Wed Oct 26 02:38:19 2011
New Revision: 143021

URL: http://llvm.org/viewvc/llvm-project?rev=143021&view=rev
Log:
Compute the promoted integer type of fixed-width enums correctly.  Found by inspection.


Added:
    cfe/trunk/test/CXX/conv/conv.prom/p4.cpp
Modified:
    cfe/trunk/lib/Sema/SemaDecl.cpp

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=143021&r1=143020&r2=143021&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Wed Oct 26 02:38:19 2011
@@ -9702,7 +9702,11 @@
     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.

Added: cfe/trunk/test/CXX/conv/conv.prom/p4.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/conv/conv.prom/p4.cpp?rev=143021&view=auto
==============================================================================
--- cfe/trunk/test/CXX/conv/conv.prom/p4.cpp (added)
+++ cfe/trunk/test/CXX/conv/conv.prom/p4.cpp Wed Oct 26 02:38:19 2011
@@ -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;





More information about the cfe-commits mailing list