[PATCH 3/6] Emit macro expansion related diagnostics

Dodji Seketeli dodji@redhat.com
Tue Dec 14 07:28:00 GMT 2010


Paolo Bonzini <bonzini@gnu.org> writes:

>
> test.c:5:14: error: invalid operands to binary<<  (have ‘double’ and ‘int’)
> test.c:2:9: note: while expanding macro 'OPERATE'
> test.c:5:14: note: while expanding macro 'SHIFTL'
> test.c:8:3: note: while expanding macro 'MULT'
> test.c:13:3: note: expanded from here
>

In the absence of caret diagnostic I think it is useful to explicitely
make the difference between a location in the definition of the macro,
and the location of the macro expansion point, i.e:

In this error message:

test.c: In function ‘g’:
test.c:5:14: error: invalid operands to binary << (have ‘double’ and ‘int’)
In macro 'OPERATE' at test.c:2:9
    Expanded at test.c:5:3

[...]

Here is what we are trying to show:

     1    #define OPERATE(OPRD1, OPRT, OPRD2) \
     2      OPRD1 OPRT OPRD2;
                  ^
                  |
                  ---< location in the /definition/ of OPERATE
                       pointed to by: "In macro OPERATE at test.c:2:9"
     3
     4    #define SHIFTL(A,B) \
     5      OPERATE (A,<<,B)
            ^
            |
            ---< location of /expansion point/ of OPERATE
                 pointed to by "Expanded at test.c:5:3"

[...]


I think that's more explicit (and informative) than just saying:

> test.c:5:14: error: invalid operands to binary<<  (have ‘double’ and ‘int’)
> test.c:2:9: note: while expanding macro 'OPERATE'
> test.c:5:14: note: while expanding macro 'SHIFTL'

But when we have caret diagnostic where we actually show the user the
code we are talking about we can use the "while expanding" just fine.

-- 
	Dodji



More information about the Gcc-patches mailing list