<div>Richard, thank you very much for the answer!</div><div> </div><div><em>>>I suspect the problem is either something you elided in the above code or it's an issue with the compilation flags in use, because the above example in isolation looks fine</em></div><div>Yes, exactly!</div><div> </div><div>In fact David already helps me to find the problem )</div><div>Sorry i didnt wrote it here, used such mailing list first time!</div><div> </div><div>I have create a minimal example which helps me to catch it</div><div><div><div>It seems that i have specified language options too late ... :</div><div> </div><div><div>data/input.cpp:1:10: error: unknown type name 'class'</div><div>template<class T></div></div></div><div> </div><div><a href="https://github.com/FROL256/clang_parse_ast_example/blob/main/main.cpp" rel="noopener noreferrer" target="_blank">https://github.com/FROL256/clang_parse_ast_example/blob/main/main.cpp</a></div><div> </div><div><a href="https://github.com/FROL256/clang_parse_ast_example/blob/main/main.cpp(lines%20162--170,%20wrong%20way,%20too%20late)(lines%20148--155,%20right%20way,%20works)">(lines 162--170, wrong way, too late)</a></div><div><div><a href="https://github.com/FROL256/clang_parse_ast_example/blob/main/main.cpp(lines%20162--170,%20wrong%20way,%20too%20late)(lines%20148--155,%20right%20way,%20works)">(lines 148--155, right way, works)</a></div></div></div><div> </div><div>I think that in my main project i didn't got such error message (unknown type name 'class') due to other errors related to missed includes.</div><div>After I add some stl types definition and some functions from <cmath> to processed source code, .... then finally i got AST parsed correcty.</div><div> </div><div>Thank you very much, clang is awesome!</div><div> </div><div> </div><div>15.12.2020, 10:15, "Richard Smith" <richard@metafoo.co.uk>:</div><blockquote><div><div>On Thu, 3 Dec 2020 at 04:02, Владимир Фролов via cfe-users <<a href="mailto:cfe-users@lists.llvm.org" rel="noopener noreferrer">cfe-users@lists.llvm.org</a>> wrote:</div><div><blockquote style="border-left-color:rgb( 204 , 204 , 204 );border-left-style:solid;border-left-width:1px;margin:0px 0px 0px 0.8ex;padding-left:1ex"><div>Greetings! I'm using clang for source-to-source translation.</div><div> </div><div>Recently I got a problem with parsing code which use templates.</div><div>First, here is the working example:</div><div> </div><div><div><span style="font-family:'courier new' , monospace">struct MyTestVector2</span></div><div><span style="font-family:'courier new' , monospace">{<!-- --></span></div><div><span style="font-family:'courier new' , monospace"> unsigned int _data[6];</span></div><div><span style="font-family:'courier new' , monospace"> unsigned int * data() { return &_data[0]; }</span></div><div><span style="font-family:'courier new' , monospace">};</span></div></div><div><span style="font-family:'courier new' , monospace">... </span></div><div><div><span style="font-family:'courier new' , monospace">MyTestVector2 testData2;</span></div><div><span style="font-family:'courier new' , monospace">kernel_TestColor(&hit, </span></div><div><span style="font-family:'courier new' , monospace">                testData2.data(), tidX, tidY);</span></div></div><div>This code processed normally and i gon correct "CXXMemberCallExpr" node for kernel_TestColor which i actually need.</div><div>Then i changed MyTestVector2 to template:</div><div> </div><div><div><span style="font-family:'courier new' , monospace">template<class T></span></div><div><span style="font-family:'courier new' , monospace">struct MyTestVector2</span></div><div><span style="font-family:'courier new' , monospace">{<!-- --></span></div><div><span style="font-family:'courier new' , monospace"> T _data[6];</span></div><div><span style="font-family:'courier new' , monospace"> T * data() { return &_data[0]; }</span></div><div><span style="font-family:'courier new' , monospace">};</span></div><div> </div><div><span style="font-family:'courier new' , monospace">...</span></div><div><span style="font-family:'courier new' , monospace">MyTestVector2<unsigned int> testData2;</span></div><div><span style="font-family:'courier new' , monospace">kernel_TestColor(&hit,</span></div><div><span style="font-family:'courier new' , monospace">                testData2.data(), tidX, tidY);</span></div><div> </div></div><div>This time i got</div><div> </div><div><div>`-DeclStmt 0x55555816e128 <line:59:3, col:40></div><div>  `-VarDecl 0x55555816e0c0 <col:3, col:31> col:31 invalid testData2 'MyTestVector2<unsigned int>':'MyTestVector2<unsigned int>'</div></div><div> </div><div>This time, The AST node for <span style="font-family:'courier new' , monospace">kernel_TestColor is just missed!</span></div><div><div>The code is absolutely correct itself, it can be build and run.</div></div></blockquote><div> </div><div>What interface are you using to parse the code with Clang? (libclang? libTooling? Direct use of the C++ API?)</div><div> </div><div>The above AST dump shows that Clang thinks the declaration of the variable 'testData2' is invalid (see the "invaild" in the declaration). Clang should also have produced a diagnostic message explaining this, but some of the ways of using Clang as a library don't set up a diagnostic consumer by default, meaning that error message is just being thrown away. If you set up a diagnostic consumer, Clang should tell you what's going wrong.</div><div> </div><div>I suspect the problem is either something you elided in the above code or it's an issue with the compilation flags in use, because the above example in isolation looks fine.</div><div> </div><blockquote style="border-left-color:rgb( 204 , 204 , 204 );border-left-style:solid;border-left-width:1px;margin:0px 0px 0px 0.8ex;padding-left:1ex"><div> </div><div>I'm using AST processing for code generation, so it is important for me to get  AST node for <span style="font-family:'courier new' , monospace">kernel_TestColor</span> and then analyze its arguments.</div><div>I understand that this seems to be not a bug, but ... may be, there is a way to make parser more tolerant to data types ... because what i actually need is just a strings of all parameters, so, just having "<span style="font-family:'courier new' , monospace">testData2.data()</span>" at some level of AST for the second parameter of <span style="font-family:'courier new' , monospace">kernel_TestColor would be enough for me</span>.</div><div> </div><div>I would be appretiate for help or advice.</div><div>Currently i use llvm 10.</div><div><div>Thanks!</div></div><div>-- </div><div>Best Regards,</div><div> Frolov V.A.</div><div> </div>_______________________________________________<br />cfe-users mailing list<br /><a href="mailto:cfe-users@lists.llvm.org" rel="noopener noreferrer" target="_blank">cfe-users@lists.llvm.org</a><br /><a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users" rel="noopener noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users</a></blockquote></div></div></blockquote><div> </div><div> </div><div>-- </div><div>С уважением,</div><div>Фролов В. А.</div><div> </div>