[cfe-commits] r130399 - in /cfe/trunk: lib/Parse/ParseDecl.cpp test/SemaCXX/libstdcxx_is_pod_hack.cpp

Douglas Gregor dgregor at apple.com
Thu Apr 28 08:48:45 PDT 2011


Author: dgregor
Date: Thu Apr 28 10:48:45 2011
New Revision: 130399

URL: http://llvm.org/viewvc/llvm-project?rev=130399&view=rev
Log:
libstdc++ 4.4 uses __is_signed as an identifier, while Clang treats it
as a keyword for the __is_signed type trait. Cope with this conflict
via some hackish recovery: if we see a declaration of the form

 static const bool __is_signed

then we stop treating __is_signed as a keyword and instead treat it as
an identifier. It's ugly, but it's better than making the __is_signed
type trait conditional on some language flag. Fixes PR9804.


Modified:
    cfe/trunk/lib/Parse/ParseDecl.cpp
    cfe/trunk/test/SemaCXX/libstdcxx_is_pod_hack.cpp

Modified: cfe/trunk/lib/Parse/ParseDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=130399&r1=130398&r2=130399&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDecl.cpp Thu Apr 28 10:48:45 2011
@@ -1479,6 +1479,24 @@
       continue;
     }
 
+    case tok::kw___is_signed:
+      // GNU libstdc++ 4.4 uses __is_signed as an identifier, but Clang
+      // typically treats it as a trait. If we see __is_signed as it appears
+      // in libstdc++, e.g.,
+      //
+      //   static const bool __is_signed;
+      //
+      // then treat __is_signed as an identifier rather than as a keyword.
+      if (DS.getTypeSpecType() == TST_bool &&
+          DS.getTypeQualifiers() == DeclSpec::TQ_const &&
+          DS.getStorageClassSpec() == DeclSpec::SCS_static) {
+        Tok.getIdentifierInfo()->RevertTokenIDToIdentifier();
+        Tok.setKind(tok::identifier);
+      }
+
+      // We're done with the declaration-specifiers.
+      goto DoneWithDeclSpec;
+        
       // typedef-name
     case tok::identifier: {
       // In C++, check to see if this is a scope specifier like foo::bar::, if

Modified: cfe/trunk/test/SemaCXX/libstdcxx_is_pod_hack.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/libstdcxx_is_pod_hack.cpp?rev=130399&r1=130398&r2=130399&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/libstdcxx_is_pod_hack.cpp (original)
+++ cfe/trunk/test/SemaCXX/libstdcxx_is_pod_hack.cpp Thu Apr 28 10:48:45 2011
@@ -11,3 +11,12 @@
 };
 
 __is_pod<int> ipi;
+
+// Another, similar egregious hack for __is_signed, which is a type
+// trait in Embarcadero's compiler but is used as an identifier in
+// libstdc++.
+struct test_is_signed {
+  static const bool __is_signed = true;
+};
+
+bool check_signed = test_is_signed::__is_signed;





More information about the cfe-commits mailing list