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

Fariborz Jahanian fjahanian at apple.com
Fri Sep 4 08:19:47 PDT 2009


This could be related:

union __is_pod {
    int i;
};

$CLANG s.cpp
s.cpp:1:1: error: declaration of anonymous union must be a definition
union __is_pod {
^
s.cpp:1:1: error: declaration does not declare anything
union __is_pod {

Renaming __is_pod fixes the problem.

- Fariborz

On Sep 3, 2009, at 10:53 PM, Douglas Gregor wrote:

> Author: dgregor
> Date: Fri Sep  4 00:53:02 2009
> New Revision: 80988
>
> URL: http://llvm.org/viewvc/llvm-project?rev=80988&view=rev
> Log:
> Introduce an egregious hack to fix PR4828.
>
> The problem this change addresses is that we treat __is_pod and
> __is_empty as keywords in C++, because they are built-in type traits
> in GCC >= 4.3. However, GNU libstdc++ 4.2 (and possibly earlier
> versions) define implementation-detail struct templates named __is_pod
> and __is_empty.
>
> This commit solves the problem by recognizing
>
>  struct __is_pod
>
> and
>
>  struct __is_empty
>
> as special token sequences. When one of these token sequences is
> encountered, the keyword (__is_pod or __is_empty) is implicitly
> downgraded to an identifier so that parsing can continue. This is an
> egregious hack, but it has the virtue of "just working" whether
> someone is using libstdc++ 4.2 or not, without the need for special
> flags.
>
>
> Added:
>    cfe/trunk/test/SemaCXX/libstdcxx_is_pod_hack.cpp   (with props)
> Modified:
>    cfe/trunk/lib/Parse/ParseDeclCXX.cpp
>
> Modified: cfe/trunk/lib/Parse/ParseDeclCXX.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDeclCXX.cpp?rev=80988&r1=80987&r2=80988&view=diff
>
> =
> =
> =
> =
> =
> =
> =
> =
> ======================================================================
> --- cfe/trunk/lib/Parse/ParseDeclCXX.cpp (original)
> +++ cfe/trunk/lib/Parse/ParseDeclCXX.cpp Fri Sep  4 00:53:02 2009
> @@ -536,6 +536,26 @@
>   if (Tok.is(tok::kw___declspec))
>     Attr = ParseMicrosoftDeclSpec(Attr);
>
> +  if (TagType == DeclSpec::TST_struct && Tok.is(tok::kw___is_pod)) {
> +    // GNU libstdc++ 4.2 uses __is_pod as the name of a struct  
> template, but
> +    // __is_pod is a keyword in GCC >= 4.3. Therefore, when we see  
> the
> +    // token sequence "struct __is_pod", make __is_pod into a normal
> +    // identifier rather than a keyword, to allow libstdc++ 4.2 to  
> work
> +    // properly.
> +    Tok.getIdentifierInfo()->setTokenID(tok::identifier);
> +    Tok.setKind(tok::identifier);
> +  }
> +
> +  if (TagType == DeclSpec::TST_struct &&  
> Tok.is(tok::kw___is_empty)) {
> +    // GNU libstdc++ 4.2 uses __is_empty as the name of a struct  
> template, but
> +    // __is_empty is a keyword in GCC >= 4.3. Therefore, when we  
> see the
> +    // token sequence "struct __is_empty", make __is_empty into a  
> normal
> +    // identifier rather than a keyword, to allow libstdc++ 4.2 to  
> work
> +    // properly.
> +    Tok.getIdentifierInfo()->setTokenID(tok::identifier);
> +    Tok.setKind(tok::identifier);
> +  }
> +
>   // Parse the (optional) nested-name-specifier.
>   CXXScopeSpec SS;
>   if (getLang().CPlusPlus &&
>
> Added: 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=80988&view=auto
>
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- cfe/trunk/test/SemaCXX/libstdcxx_is_pod_hack.cpp (added)
> +++ cfe/trunk/test/SemaCXX/libstdcxx_is_pod_hack.cpp Fri Sep  4  
> 00:53:02 2009
> @@ -0,0 +1,7 @@
> +// RUN: clang-cc -fsyntax-only %s
> +
> +template<typename T>
> +struct __is_pod {
> +};
> +
> +__is_pod<int> ipi;
>
> Propchange: cfe/trunk/test/SemaCXX/libstdcxx_is_pod_hack.cpp
>
> ------------------------------------------------------------------------------
>    svn:eol-style = native
>
> Propchange: cfe/trunk/test/SemaCXX/libstdcxx_is_pod_hack.cpp
>
> ------------------------------------------------------------------------------
>    svn:keywords = Id
>
> Propchange: cfe/trunk/test/SemaCXX/libstdcxx_is_pod_hack.cpp
>
> ------------------------------------------------------------------------------
>    svn:mime-type = text/plain
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits




More information about the cfe-commits mailing list