[cfe-commits] r84968 - in /cfe/trunk: include/clang/Basic/DiagnosticParseKinds.td lib/Parse/ParseExpr.cpp lib/Sema/SemaExprCXX.cpp test/Parser/cxx-parse-member-pointer-op.cpp

Chris Lattner clattner at apple.com
Fri Oct 23 21:47:01 PDT 2009


On Oct 23, 2009, at 2:01 PM, Fariborz Jahanian wrote:

> Author: fjahanian
> Date: Fri Oct 23 16:01:39 2009
> New Revision: 84968
>
> URL: http://llvm.org/viewvc/llvm-project?rev=84968&view=rev
> Log:
> Diagnose misuse of '.*' and '->*' operators during parse
> instead of crashing in code gen.

Hi Fariborz,

Would it be feasible to offer a fixit hint to convert .*  into ->*  
(and visaversa) if the parse would work when the other operator was  
provided?  This is similar to . <-> ->

-Chris


>
>
> Added:
>    cfe/trunk/test/Parser/cxx-parse-member-pointer-op.cpp
> Modified:
>    cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
>    cfe/trunk/lib/Parse/ParseExpr.cpp
>    cfe/trunk/lib/Sema/SemaExprCXX.cpp
>
> Modified: cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td?rev=84968&r1=84967&r2=84968&view=diff
>
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td (original)
> +++ cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td Fri Oct 23  
> 16:01:39 2009
> @@ -117,6 +117,8 @@
>   "expected ';' after static_assert">;
> def err_expected_semi_for : Error<"expected ';' in 'for' statement  
> specifier">;
> def err_expected_colon_after : Error<"expected ':' after %0">;
> +def err_pointer_to_member_type : Error<
> +  "invalid use of pointer to member type after %0">;
> def err_label_end_of_compound_statement : Error<
>   "label at end of compound statement: expected statement">;
> def err_expected_string_literal : Error<"expected string literal">;
>
> Modified: cfe/trunk/lib/Parse/ParseExpr.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseExpr.cpp?rev=84968&r1=84967&r2=84968&view=diff
>
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- cfe/trunk/lib/Parse/ParseExpr.cpp (original)
> +++ cfe/trunk/lib/Parse/ParseExpr.cpp Fri Oct 23 16:01:39 2009
> @@ -340,7 +340,18 @@
>       // Eat the colon.
>       ColonLoc = ConsumeToken();
>     }
> -
> +
> +    if ((OpToken.is(tok::periodstar) || OpToken.is(tok::arrowstar))
> +         && Tok.is(tok::identifier)) {
> +      CXXScopeSpec SS;
> +      if (Actions.getTypeName(*Tok.getIdentifierInfo(),
> +                                           Tok.getLocation(),  
> CurScope, &SS)) {
> +        const char *Opc = OpToken.is(tok::periodstar) ? "'.*'" : "'- 
> >*'";
> +        Diag(OpToken, diag::err_pointer_to_member_type) << Opc;
> +        return ExprError();
> +      }
> +
> +    }
>     // Parse another leaf here for the RHS of the operator.
>     // ParseCastExpression works here because all RHS expressions in  
> C have it
>     // as a prefix, at least. However, in C++, an assignment- 
> expression could
>
> Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=84968&r1=84967&r2=84968&view=diff
>
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Fri Oct 23 16:01:39 2009
> @@ -212,7 +212,7 @@
>                           PDiag(diag::err_invalid_incomplete_type_use)
>                             << FullRange))
>     return ExprError();
> -
> +
>   if (RequireNonAbstractType(TyBeginLoc, Ty,
>                              diag::err_allocation_of_abstract_type))
>     return ExprError();
>
> Added: cfe/trunk/test/Parser/cxx-parse-member-pointer-op.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/cxx-parse-member-pointer-op.cpp?rev=84968&view=auto
>
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- cfe/trunk/test/Parser/cxx-parse-member-pointer-op.cpp (added)
> +++ cfe/trunk/test/Parser/cxx-parse-member-pointer-op.cpp Fri Oct 23  
> 16:01:39 2009
> @@ -0,0 +1,13 @@
> +// RUN: clang-cc -fsyntax-only -pedantic -verify %s
> +
> +struct C {};
> +
> +typedef void (C::*pmfc)();
> +
> +void g(pmfc) {
> +  C *c;
> +  c->*pmfc(); // expected-error {{invalid use of pointer to member  
> type after '->*'}}
> +  C c1;
> +  c1.*pmfc(); // expected-error {{invalid use of pointer to member  
> type after '.*'}}
> +}
> +
>
>
> _______________________________________________
> 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