[PATCH] Fixed error recovery if sizeof is used without parenthesis
Rafael EspĂndola
rafael.espindola at gmail.com
Mon Jan 13 10:25:01 PST 2014
ccing Alp.
On 13 January 2014 01:06, Serge Pavlov <sepavloff at gmail.com> wrote:
> Any comments?
>
>
> 2013/12/19 Serge Pavlov <sepavloff at gmail.com>
>>
>> sepavloff added you to the CC list for the revision "Fixed error recovery
>> if sizeof is used without parenthesis".
>>
>> Changes made in r192200 fixed PR16992, which requested fixit suggesting
>> parenthesis if sizeof is followed by type-id. However expression in form
>> T() followed by ')' was incorrectly considered as a type-id if 'T' is
>> typedef name. This change fixes this case.
>>
>> http://llvm-reviews.chandlerc.com/D2440
>>
>> Files:
>> include/clang/Parse/Parser.h
>> lib/Parse/ParseExpr.cpp
>> lib/Parse/ParseTentative.cpp
>> test/SemaCXX/expressions.cpp
>>
>> Index: include/clang/Parse/Parser.h
>> ===================================================================
>> --- include/clang/Parse/Parser.h
>> +++ include/clang/Parse/Parser.h
>> @@ -1772,6 +1772,7 @@
>> /// disambiguation will occur.
>> enum TentativeCXXTypeIdContext {
>> TypeIdInParens,
>> + TypeIdSeparate,
>> TypeIdAsTemplateArgument
>> };
>>
>> @@ -1790,6 +1791,16 @@
>> return isTypeIdInParens(isAmbiguous);
>> }
>>
>> + /// \brief Checks if the current tokens form type-id or expression.
>> + /// It is similar to isTypeIdInParens but does not suppose that type-id
>> + /// is in parenthesis.
>> + bool isTypeIdSeparate(bool &isAmbiguous) {
>> + if (getLangOpts().CPlusPlus)
>> + return isCXXTypeId(TypeIdSeparate, isAmbiguous);
>> + isAmbiguous = false;
>> + return isTypeSpecifierQualifier();
>> + }
>> +
>> /// isCXXDeclarationStatement - C++-specialized function that
>> disambiguates
>> /// between a declaration or an expression statement, when parsing
>> function
>> /// bodies. Returns true for declaration, false for expression.
>> Index: lib/Parse/ParseExpr.cpp
>> ===================================================================
>> --- lib/Parse/ParseExpr.cpp
>> +++ lib/Parse/ParseExpr.cpp
>> @@ -1493,7 +1493,7 @@
>> if (OpTok.is(tok::kw_sizeof) || OpTok.is(tok::kw___alignof) ||
>> OpTok.is(tok::kw_alignof) || OpTok.is(tok::kw__Alignof)) {
>> bool isAmbiguousTypeId;
>> - if (isTypeIdInParens(isAmbiguousTypeId)) {
>> + if (isTypeIdSeparate(isAmbiguousTypeId)) {
>> DeclSpec DS(AttrFactory);
>> ParseSpecifierQualifierList(DS);
>> Declarator DeclaratorInfo(DS, Declarator::TypeNameContext);
>> Index: lib/Parse/ParseTentative.cpp
>> ===================================================================
>> --- lib/Parse/ParseTentative.cpp
>> +++ lib/Parse/ParseTentative.cpp
>> @@ -437,9 +437,12 @@
>> TPR = TPResult::True();
>>
>> if (TPR == TPResult::Ambiguous()) {
>> + if (Context == TypeIdSeparate)
>> + TPR = TPResult::False();
>> +
>> // We are supposed to be inside parens, so if after the abstract
>> declarator
>> // we encounter a ')' this is a type-id, otherwise it's an
>> expression.
>> - if (Context == TypeIdInParens && Tok.is(tok::r_paren)) {
>> + else if (Context == TypeIdInParens && Tok.is(tok::r_paren)) {
>> TPR = TPResult::True();
>> isAmbiguous = true;
>>
>> Index: test/SemaCXX/expressions.cpp
>> ===================================================================
>> --- test/SemaCXX/expressions.cpp
>> +++ test/SemaCXX/expressions.cpp
>> @@ -118,3 +118,10 @@
>> (void)s1.foo();
>> (void)s2.foo();
>> }
>> +
>> +namespace pr16992 {
>> + typedef int T;
>> + unsigned getsz() {
>> + return (sizeof T());
>> + }
>> +}
>>
>> _______________________________________________
>> cfe-commits mailing list
>> cfe-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>>
>
>
>
> --
> Thanks,
> --Serge
>
> _______________________________________________
> 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