r224912 - Sema: Don't crash when solitary :: token appears before { in struct def

Richard Smith richard at metafoo.co.uk
Sun Dec 28 21:53:03 PST 2014


Perhaps we should drop the qualifier in the parser in this case; this
doesn't match the grammar and it doesn't make a lot of sense to propagate
this weird broken state all the way into the AST.
On 29 Dec 2014 05:21, "David Majnemer" <david.majnemer at gmail.com> wrote:

> Author: majnemer
> Date: Sun Dec 28 23:17:46 2014
> New Revision: 224912
>
> URL: http://llvm.org/viewvc/llvm-project?rev=224912&view=rev
> Log:
> Sema: Don't crash when solitary :: token appears before { in struct def
>
> hasDeclaratorForAnonDecl, getDeclaratorForAnonDecl and
> getTypedefNameForAnonDecl are expected to handle the case where
> NamedDeclOrQualifier holds the wrong type or nothing at all.
>
> Modified:
>     cfe/trunk/include/clang/AST/Decl.h
>     cfe/trunk/lib/Sema/SemaDecl.cpp
>     cfe/trunk/test/CXX/dcl.decl/dcl.meaning/p1.cpp
>
> Modified: cfe/trunk/include/clang/AST/Decl.h
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=224912&r1=224911&r2=224912&view=diff
>
> ==============================================================================
> --- cfe/trunk/include/clang/AST/Decl.h (original)
> +++ cfe/trunk/include/clang/AST/Decl.h Sun Dec 28 23:17:46 2014
> @@ -2823,16 +2823,18 @@ public:
>
>    bool hasDeclaratorForAnonDecl() const {
>      return dyn_cast_or_null<DeclaratorDecl>(
> -        NamedDeclOrQualifier.get<NamedDecl *>());
> +        NamedDeclOrQualifier.dyn_cast<NamedDecl *>());
>    }
>    DeclaratorDecl *getDeclaratorForAnonDecl() const {
> -    return hasExtInfo() ? nullptr : dyn_cast_or_null<DeclaratorDecl>(
> -                                  NamedDeclOrQualifier.get<NamedDecl
> *>());
> +    return hasExtInfo() ? nullptr
> +                        : dyn_cast_or_null<DeclaratorDecl>(
> +                              NamedDeclOrQualifier.dyn_cast<NamedDecl
> *>());
>    }
>
>    TypedefNameDecl *getTypedefNameForAnonDecl() const {
> -    return hasExtInfo() ? nullptr : dyn_cast_or_null<TypedefNameDecl>(
> -                                  NamedDeclOrQualifier.get<NamedDecl
> *>());
> +    return hasExtInfo() ? nullptr
> +                        : dyn_cast_or_null<TypedefNameDecl>(
> +                              NamedDeclOrQualifier.dyn_cast<NamedDecl
> *>());
>    }
>
>    void setDeclaratorForAnonDecl(DeclaratorDecl *DD) {
> NamedDeclOrQualifier = DD; }
>
> Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=224912&r1=224911&r2=224912&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaDecl.cpp Sun Dec 28 23:17:46 2014
> @@ -11790,7 +11790,7 @@ CreateNewDecl:
>        // CheckMemberSpecialization, below.
>        if (!isExplicitSpecialization &&
>            (TUK == TUK_Definition || TUK == TUK_Declaration) &&
> -          diagnoseQualifiedDeclaration(SS, DC, OrigName, NameLoc))
> +          diagnoseQualifiedDeclaration(SS, DC, OrigName, Loc))
>          Invalid = true;
>
>        New->setQualifierInfo(SS.getWithLocInContext(Context));
>
> Modified: cfe/trunk/test/CXX/dcl.decl/dcl.meaning/p1.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/dcl.decl/dcl.meaning/p1.cpp?rev=224912&r1=224911&r2=224912&view=diff
>
> ==============================================================================
> --- cfe/trunk/test/CXX/dcl.decl/dcl.meaning/p1.cpp (original)
> +++ cfe/trunk/test/CXX/dcl.decl/dcl.meaning/p1.cpp Sun Dec 28 23:17:46 2014
> @@ -43,3 +43,6 @@ namespace NS {
>    template<typename T> struct NS::Y { }; // expected-warning{{extra
> qualification on member 'Y'}}
>    template<typename T> void NS::wibble(T) { } // expected-warning{{extra
> qualification on member 'wibble'}}
>  }
> +
> +// expected-warning at +1{{extra qualification on member}}
> +struct ::{} a; // expected-error{{expected identifier}}
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20141228/0b2b1b8d/attachment.html>


More information about the cfe-commits mailing list