gcc compiler flag to suppress template expansion for template errors during compilation?

僤鯓⒐⒋嵵緔 提交于 2020-02-21 13:18:49

问题


I'm wondering if there is a flag or modification for the gcc compiler that will return a line number and sentence explaining the type of error when it encounters an error involving templates, but will not print the page of template expansion code spaghetti that invariably follow such errors.

For example, instead of an error like this:

temp.cc:9: error: ‘class std::map<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char,     std::char_traits<char>, std::allocator<char> > > > >’ has no member named ‘hat’

I would like something like this:

temp.cc:9: error: class has no member named hat.

回答1:


There isnt one. The compiler is trying to help you identify the class that is causing the problem. It only knows of that class as the expansion of its template types.




回答2:


The gcc has no flag for this, but sed could easily solve the job.



来源:https://stackoverflow.com/questions/6963892/gcc-compiler-flag-to-suppress-template-expansion-for-template-errors-during-comp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!