Jason Merrill <ja...@redhat.com> writes: > On 07/19/2011 05:42 AM, Dodji Seketeli wrote: >> If you are talking about the case of a macro A that can have (among the >> tokens of its replacement list) a token B that itself is a macro, then >> this is supported by the current setup. > > I was more thinking of the case of a macro A with a parameter X which > is passed to macro B, and then macro C: > > 1: #define A(X) B(X) > 2: #define B(X) C(X) > 3: #define C(X) X+2 > 4: > 5: A(blah)
So, let's consider a similar example then: $ cat -n test12.c 1 int var; 2 #define A(X) B(X) 3 #define B(X) C(X) 4 #define C(X) 2+X 5 6 int 7 foo (void) 8 { 9 return A(blah()); 10 } $ ./cc1 -ftrack-macro-expansion -quiet ../../prtests/test12.c test12.c: In function ‘foo’: test12.c:9:15: erreur: called object ‘var’ is not a function test12.c:4:16: note: in expansion of macro 'C' test12.c:3:14: note: expanded from here test12.c:3:16: note: in expansion of macro 'B' test12.c:2:14: note: expanded from here test12.c:2:16: note: in expansion of macro 'A' test12.c:9:10: note: expanded from here > > what is the replacement point of "blah"? Is it the use of X on line > 3? There are going to be 3 macro expansions happening successively. Eventually, in the context of the expansion of C (indirectly triggered by the expansion of A), yes, the replacement point of "blah" is going to be the use of X at line 3. On my example, the corresponds to the diagnostic line: test12.c:4:16: note: in expansion of macro 'C' > It seems that we can only have information about the X in one of > the macro definitions. That is true, in the context of a given macro expansion, e.g, in the context of the expansion of the macro A, in A(blah). But then, when libcpp is requested to get the next token (e.g, after expanding A(blah) into B(blah)) it finds out that the next token B is a macro itself. It then expands that macro in a new expansion context. So we have information about the X in the context of B. We eventually reach the expansion context of C that way. -- Dodji