[cfe-dev] Tooling vs -fdelayed-template-parsing WAS: Clang-cl.exe and the VC++ preprocessor
Reid Kleckner
rnk at google.com
Mon Aug 4 10:34:27 PDT 2014
On Mon, Aug 4, 2014 at 10:26 AM, Kim Gräsman <kim.grasman at gmail.com> wrote:
> On Mon, Aug 4, 2014 at 7:14 PM, Manuel Klimek <klimek at google.com> wrote:
>
>>
>> why are those not instantiated when a FrontendAction is run?
>>
>
> My choice of words was bad -- the template is not instantiated here,
> merely parsed. We don't have any template arguments to give it.
>
> We just (a few minutes ago, while experimenting with this) found a case
> where late-parsing a template whose body contains undefined symbols would
> generate an incomplete AST, e.g.
>
> template<class T>
> void foo(const T& t) {
> UndefinedSymbol::bar(t); // colon-colon
> }
>
> $ clang-check.exe -ast-dump incomplete.cpp -- -fno-delayed-template-parsing
> TranslationUnitDecl 0xebe7e0 <<invalid sloc>> <invalid sloc>
> |-CXXRecordDecl 0xebeaa0 <<invalid sloc>> <invalid sloc> implicit class
> type_info
> |-TypedefDecl 0xebeb20 <<invalid sloc>> <invalid sloc> implicit size_t
> 'unsigned int'
> |-TypedefDecl 0xebeb80 <<invalid sloc>> <invalid sloc> implicit
> __builtin_va_list 'char *'
> `-FunctionTemplateDecl 0xebed80 <incomplete.cpp:2:1, line:5:1> line:3:6 foo
> |-TemplateTypeParmDecl 0xebebb0 <line:2:10, col:16> col:16 class T
> `-FunctionDecl 0xebed10 <line:3:1, line:5:1> line:3:6 foo 'void (const T
> &)'
> |-ParmVarDecl 0xebec80 <col:10, col:19> col:19 referenced t 'const T &'
> `-CompoundStmt 0xebee40 <col:22, line:5:1>
> `-CallExpr 0xebee20 <line:4:3, col:25> '<dependent type>'
> |-DependentScopeDeclRefExpr 0xebede0 <col:3, col:20> '<dependent
> type>' lvalue
> `-DeclRefExpr 0xebee04 <col:24> 'const T' lvalue ParmVar 0xebec80
> 't' 'const T &'
>
> This runs without error, while this:
>
> template<class T>
> void foo(const T& t) {
> UndefinedSymbol.bar(t); // dot
> }
>
> throws an error, as expected:
>
> incomplete.cpp:4:4: error: use of undeclared identifier 'UndefinedSymbol'
> UndefinedSymbol.bar(t);
> ^
>
> I don't know if this is a general bug in the parser, but it'd be nice to
> always get a diagnostic here.
>
This is an -fms-compatibility hack, which is separate from delayed template
parsing. I'm surprised we don't have a -Wmicrosoft warning here, though.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20140804/7c10509c/attachment.html>
More information about the cfe-dev
mailing list