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

Richard Smith richard at metafoo.co.uk
Mon Dec 29 04:18:09 PST 2014


LGTM. "expected identifier before '{'" would also work; I don't think this
needs its own custom diagnostic.
On 29 Dec 2014 10:05, "David Majnemer" <david.majnemer at gmail.com> wrote:

> Perhaps something like the following?
>
> diff --git a/include/clang/Basic/DiagnosticParseKinds.td
> b/include/clang/Basic/DiagnosticParseKinds.td
> index f39c2b8..f176370 100644
> --- a/include/clang/Basic/DiagnosticParseKinds.td
> +++ b/include/clang/Basic/DiagnosticParseKinds.td
> @@ -374,6 +374,8 @@ def warn_cxx98_compat_static_assert : Warning<
>    InGroup<CXX98Compat>, DefaultIgnore;
>  def err_paren_after_colon_colon : Error<
>    "unexpected parenthesis after '::'">;
> +def err_brace_after_colon_colon : Error<
> +  "unexpected brace after '::'">;
>  def err_function_definition_not_allowed : Error<
>    "function definition is not allowed here">;
>  def err_expected_end_of_enumerator : Error<
> diff --git a/lib/Parse/ParseExprCXX.cpp b/lib/Parse/ParseExprCXX.cpp
> index dad1f0d..7968a01 100644
> --- a/lib/Parse/ParseExprCXX.cpp
> +++ b/lib/Parse/ParseExprCXX.cpp
> @@ -219,13 +219,20 @@ bool
> Parser::ParseOptionalCXXScopeSpecifier(CXXScopeSpec &SS,
>      if (NextKind == tok::kw_new || NextKind == tok::kw_delete)
>        return false;
>
> -    // '::' - Global scope qualifier.
> -    if (Actions.ActOnCXXGlobalScopeSpecifier(ConsumeToken(), SS))
> -      return true;
> +    if (NextKind == tok::l_brace) {
> +      // It is invalid to have :: {, consume the scope qualifier and
> pretend
> +      // like we never saw it.
> +      SourceLocation ColonColonLoc = ConsumeToken();
> +      Diag(ColonColonLoc, diag::err_brace_after_colon_colon);
> +    } else {
> +      // '::' - Global scope qualifier.
> +      if (Actions.ActOnCXXGlobalScopeSpecifier(ConsumeToken(), SS))
> +        return true;
>
> -    CheckForLParenAfterColonColon();
> +      CheckForLParenAfterColonColon();
>
> -    HasScopeSpecifier = true;
> +      HasScopeSpecifier = true;
> +    }
>    }
>
>    if (Tok.is(tok::kw___super)) {
>
> On Mon, Dec 29, 2014 at 12:53 AM, Richard Smith <richard at metafoo.co.uk>
> wrote:
>
>> 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/20141229/63cfa36d/attachment.html>


More information about the cfe-commits mailing list