[cfe-dev] My first patch to clang

Nicola Gigante nicola.gigante at gmail.com
Sun Dec 6 04:55:19 PST 2009

Il giorno 05/dic/2009, alle ore 20.23, John McCall ha scritto:
> That isn't quite what I meant.  You've inserted it like this:
>   if (const RecordType *RTy = BaseType->getAs<RecordType>()) {
> +		
> +		if(!IsArrow && BaseType->isPointerType()) {
> This can never be satisfied, because it's inside an 'if' statement that checks whether the type is a record type.  A type can't be both a record type and a pointer type!
Yes, that's a stupid mistake..

> Exactly.  You should change the input to look exactly like it would look if the user had typed '->' instead.  That's why you want your check to run before LookupMemberExpr tries to adjust the base type to the pointee type and so on.

I think I've understood what you mean. I've attached Yet Another Patch :) In the meantime, I noticed that the case of a '.' used for a pointer was similar, so I generalized the suggestion. Now I think it works, because this source code:

#include <stdio.h>

struct type
  int member;

int main()
        struct type *p_struct;
        int *p_int;
        int a_int;
        struct type a_struct;

        p_struct.member = 7;
        p_int.member = 7;
        a_struct->member = 7;
        a_int->member = 7;

        return 0;

Produces this output:

prova.c:15:10: error: member reference type 'struct type *' is a pointer; maybe you meant to use '->'?
        p_struct.member = 7;
prova.c:16:8: error: member reference base type 'int *' is not a structure or union
        p_int.member = 7;
        ~~~~~ ^
prova.c:17:10: error: member reference type 'struct type' is not a pointer; maybe you meant to use '.'?
        a_struct->member = 7;
prova.c:18:9: error: member reference type 'int' is not a pointer
        a_int->member = 7;
        ~~~~~  ^
4 diagnostics generated.

I think it's the right output. The only thing I can't understand is: All the four errors use BaseExpr->getSourceRange() to get the range of the base expressions, but in the first and the third errors (the two added by my patch), the range is wrong because also includes the arrow (or the dot). Is it my fault?

Bye bye,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: member_pointer_suggestion.patch
Type: application/octet-stream
Size: 3948 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20091206/aeeb75bd/attachment.obj>

More information about the cfe-dev mailing list