[cfe-dev] SourceRange for an extern template declaration

Eli Bendersky eliben at google.com
Thu Aug 14 16:33:57 PDT 2014


Thanks for the clarification, Richard. I've opened
http://llvm.org/bugs/show_bug.cgi?id=20666 to track this.


On Tue, Aug 12, 2014 at 12:05 PM, Richard Smith <richard at metafoo.co.uk>
wrote:

> On Tue, Aug 12, 2014 at 8:54 AM, Eli Bendersky <eliben at google.com> wrote:
>
>> Hello,
>>
>> We may be observing an invalid SourceRange being attached to an extern
>> template declaration. Consider this code:
>>
>>   template <typename T>
>>   int __ostream_insert() {
>>     return 0;
>>   }
>>
>>   extern template int __ostream_insert<char>();
>>
>>   template<> int __ostream_insert<long>() {
>>     return 1;
>>   }
>>
>> The AST dump for it is:
>>
>>     TranslationUnitDecl 0x3763300 <<invalid sloc>> <invalid sloc>
>>     |-TypedefDecl 0x3763840 <<invalid sloc>> <invalid sloc> implicit
>> __int128_t '__int128'
>>     |-TypedefDecl 0x37638a0 <<invalid sloc>> <invalid sloc> implicit
>> __uint128_t 'unsigned __int128'
>>     |-TypedefDecl 0x3763c60 <<invalid sloc>> <invalid sloc> implicit
>> __builtin_va_list '__va_list_tag [1]'
>>     |-FunctionTemplateDecl 0x3763e50 </tmp/jp.cpp:1:3, line:4:3> line:2:7
>> __ostream_insert
>>     | |-TemplateTypeParmDecl 0x3763cb0 <line:1:13, col:22> col:22
>> typename T
>>     | |-FunctionDecl 0x3763db0 <line:2:3, line:4:3> line:2:7
>> __ostream_insert 'int (void)'
>>     | | `-CompoundStmt 0x3763ed8 <col:26, line:4:3>
>>     | |   `-ReturnStmt 0x3763eb8 <line:3:5, col:12>
>>     | |     `-IntegerLiteral 0x3763e98 <col:12> 'int' 0
>>     | |-FunctionDecl 0x37a4f60 <line:2:3, line:4:3> line:2:7
>> __ostream_insert 'int (void)'
>>     | | `-TemplateArgument type 'char'
>>     | `-Function 0x37a50a0 '__ostream_insert' 'int (void)'
>>     `-FunctionDecl 0x37a50a0 prev 0x37a51c0 <line:8:3, line:10:3>
>> line:8:18 __ostream_insert 'int (void)'
>>       |-TemplateArgument type 'long'
>>       `-CompoundStmt 0x37a5380 <col:43, line:10:3>
>>         `-ReturnStmt 0x37a5360 <line:9:5, col:12>
>>           `-IntegerLiteral 0x37a5340 <col:12> 'int' 1
>>
>>
>> Note that the node representing the extern declaration has the source
>> range of the original template. Is this a (known) bug, or am I
>> misunderstanding something?
>>
>
> This is certainly a bug. Note that we don't have a declaration of
> __ostream_insert<char> lexically within the TU either; we don't create any
> explicit representation of it. See this FIXME:
>
> http://clang.llvm.org/doxygen/SemaTemplate_8cpp_source.html#l07688
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20140814/058d5223/attachment.html>


More information about the cfe-dev mailing list