]> granicus.if.org Git - clang/commitdiff
Make sure C-specific enum warning doesn't trigger in C++.
authorEli Friedman <eli.friedman@gmail.com>
Wed, 16 Dec 2009 20:30:08 +0000 (20:30 +0000)
committerEli Friedman <eli.friedman@gmail.com>
Wed, 16 Dec 2009 20:30:08 +0000 (20:30 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@91563 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDecl.cpp
test/SemaCXX/enum.cpp

index bf5b350da0d51915f34488cf9d738cb124090a56..ca42cac72c8aab8c03db7ddd7f4fe52e1a506124 100644 (file)
@@ -5812,7 +5812,7 @@ void Sema::ActOnEnumBody(SourceLocation EnumLoc, SourceLocation LBraceLoc,
     const llvm::APSInt &InitVal = ECD->getInitVal();
     assert(InitVal.getBitWidth() >= IntWidth &&
            "Should have promoted value to int");
-    if (InitVal.getBitWidth() > IntWidth) {
+    if (!getLangOptions().CPlusPlus && InitVal.getBitWidth() > IntWidth) {
       llvm::APSInt V(InitVal);
       V.trunc(IntWidth);
       V.extend(InitVal.getBitWidth());
index f1bc2b2b60458c7930c283d25a744e27c519f3e4..0e4162e0d51d92437eb57f209b435a49e574e322 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -fsyntax-only -pedantic -std=c++98 -verify %s
 
 enum E {
   Val1,
@@ -42,26 +42,26 @@ namespace test1 {
   template <class A> struct is_same<A,A> { static const int value = 1; };
 
   enum enum0 { v0 };
-  int test0[is_same<typeof(+v0), int>::value];
+  int test0[is_same<__typeof(+v0), int>::value];
 
   enum enum1 { v1 = __INT_MAX__ };
-  int test1[is_same<typeof(+v1), int>::value];
+  int test1[is_same<__typeof(+v1), int>::value];
 
   enum enum2 { v2 = __INT_MAX__ * 2U };
-  int test2[is_same<typeof(+v2), unsigned int>::value];
+  int test2[is_same<__typeof(+v2), unsigned int>::value];
 
   // This kindof assumes that 'int' is smaller than 'long long'.
 #if defined(__LP64__)
-  enum enum3 { v3 = __LONG_LONG_MAX__ };
-  int test3[is_same<typeof(+v3), long>::value];
+  enum enum3 { v3 = __LONG_MAX__ };
+  int test3[is_same<__typeof(+v3), long>::value];
 
-  enum enum4 { v4 = __LONG_LONG_MAX__ * 2ULL };
-  int test4[is_same<typeof(+v4), unsigned long>::value];
+  enum enum4 { v4 = __LONG_MAX__ * 2UL };
+  int test4[is_same<__typeof(+v4), unsigned long>::value];
 #else
   enum enum3 { v3 = __LONG_LONG_MAX__ };
-  int test3[is_same<typeof(+v3), long long>::value];
+  int test3[is_same<__typeof(+v3), long long>::value];          // expected-warning {{'long long' is an extension}}
 
-  enum enum4 { v4 = __LONG_LONG_MAX__ * 2ULL };
-  int test4[is_same<typeof(+v4), unsigned long long>::value];  
+  enum enum4 { v4 = __LONG_LONG_MAX__ * 2ULL };                 // expected-warning {{'long long' is an extension}}
+  int test4[is_same<__typeof(+v4), unsigned long long>::value]; // expected-warning {{'long long' is an extension}}
 #endif
 }