This is something that came up some time ago on IRC, and several (myself, John McCall, and maybe others) really liked the idea of: systematically switch from 'instantiation' to 'expansion' in terminology relating to macros and the preprocessor. (Is there a better word than 'expand'? I couldn't come up with one. The following argument should be independent of what wording is actually chosen, except that it be different from 'instantiation'.)<div>
<br></div><div>The reasoning is two fold:</div><div>1) It more accurately describes the underlying process (token expansion), including the fact that the process happens on each use of a macro, not just on the first with a particular set of arguments, etc.</div>
<div><br></div><div>2) It helps users (and likely developers) distinguish between diagnostics and systems relating to macros vs. templates.</div><div><br></div><div>I think the second point is perhaps the most important here. As a bit of an extreme case, consider the following code:</div>
<div><br></div><div><div>% cat t5.cc</div><div>struct S1;</div><div>struct S2;</div><div>template <typename T> struct X1 { T value; };</div><div>template <typename T> struct X2 { X1<T> value; };</div><div>
#define M0 X2<S1>().value;</div><div>#define M1(x, y, z) X2<S2> foo = y</div><div>#define M2(x, y, z) M1(x, y, z)</div><div>M2(1, M0, 3);</div></div><div><br></div><div><div><div>% ./bin/clang -fsyntax-only t5.cc</div>
<div>t5.cc:3:37: error: field has incomplete type 'S1'</div><div>template <typename T> struct X1 { T value; };</div><div>                                    ^</div><div>t5.cc:4:41: note: in instantiation of template class 'X1<S1>' requested here</div>
<div>template <typename T> struct X2 { X1<T> value; };</div><div>                                        ^</div><div>t5.cc:8:7: note: in instantiation of template class 'X2<S1>' requested here</div>
<div>M2(1, M0, 3);</div><div>      ^</div><div>t5.cc:5:12: note: instantiated from:</div><div>#define M0 X2<S1>().value;</div><div>           ^</div><div>t5.cc:7:27: note: instantiated from:</div><div>#define M2(x, y, z) M1(x, y, z)</div>
<div>                          ^</div><div>t5.cc:6:34: note: instantiated from:</div><div>#define M1(x, y, z) X2<S2> foo = y</div><div>                                 ^</div></div></div><div><snip></div><div>
<br></div><div>I think it's very nice to have different wording for the macro back traces. As a bit of a straw-man, I've just replaced 'instantiated' with 'expanded' and I already find the result somewhat better:</div>
<div><br></div><div><div>% ./bin/clang -fsyntax-only t5.cc</div><div>t5.cc:3:37: error: field has incomplete type 'S1'</div><div>template <typename T> struct X1 { T value; };</div><div>                                    ^</div>
<div>t5.cc:4:41: note: in instantiation of template class 'X1<S1>' requested here</div><div>template <typename T> struct X2 { X1<T> value; };</div><div>                                        ^</div>
<div>t5.cc:8:7: note: in instantiation of template class 'X2<S1>' requested here</div><div>M2(1, M0, 3);</div><div>      ^</div><div>t5.cc:5:12: note: expanded from:</div><div>#define M0 X2<S1>().value;</div>
<div>           ^</div><div>t5.cc:7:27: note: expanded from:</div><div>#define M2(x, y, z) M1(x, y, z)</div><div>                          ^</div><div>t5.cc:6:34: note: expanded from:</div><div>#define M1(x, y, z) X2<S2> foo = y</div>
<div>                                 ^</div></div><div><br></div><div>I'd like to slowly work to move the note text to be instead:</div><div><br></div><div><div>% ./bin/clang -fsyntax-only t5.cc</div><div>t5.cc:3:37: error: field has incomplete type 'S1'</div>
<div>template <typename T> struct X1 { T value; };</div><div>                                    ^</div><div>t5.cc:4:41: note: in instantiation of template class 'X1<S1>' requested here</div><div>template <typename T> struct X2 { X1<T> value; };</div>
<div>                                        ^</div><div>t5.cc:8:7: note: in instantiation of template class 'X2<S1>' requested here</div><div>M2(1, M0, 3);</div><div>      ^</div><div>t5.cc:5:12: note: 'M0' expanded from the macro defined here:</div>
<div>#define M0 X2<S1>().value;</div><div>           ^</div><div>t5.cc:7:27: note: 'M2(...)' expanded from the macro defined here:</div><div>#define M2(x, y, z) M1(x, y, z)</div><div>                          ^</div>
<div>t5.cc:6:34: note: 'M1(...)' expanded from the macro defined here:</div><div>#define M1(x, y, z) X2<S2> foo = y</div><div>                                 ^</div></div><div><br></div><div>What do folks think? Would it be OK to work toward this in increments, starting with 'expanded from the macro defined here', and then working on a patch to add the name of the macro that we're showing the definition for?</div>
<div><br></div><div><br></div><div>As a related, but not necessary additional step, how do folks feel about moving the APIs, comments, etc inside of Clang's code itself to use the same nomenclature? I'd really like to see this as it would make reading these parts of the codebase easier in the same way I think it makes reading the diagnostics above easier. Thoughts?</div>