Search code examples
clangtypedefc++98libtooling

Clang does not parse a template with partial specialization: template < class T, class U = TYPE_A<T> > class TYPE_B;


I have example of code with template with template partial specialization. And where clang while parsing ,return result invalid declaration.

template < class T> class TYPE_A
{
};

template < class T, class U> class TYPE_B
{
};

template < class T, class U = TYPE_A<T> > class TYPE_B;

typedef TYPE_B<double> B_Test;

I have result ast dump:

TypedefDecl 0x2024d557af0 <D:\Projects\Reps\NET_Desktop\Rel\Kernel\include\OdArrayPreDef.h:60:1, col:27> col:27 invalid somethingTest 'int'
`-BuiltinType 0x2024caff080 'int'

Why clang talking (last line in dump) is invalid?


Solution

  • I tried parse only this constructions without some #include constructions.

    And parse typedef is correct.

    I found the problem to be different.

    Preprocessor try find #include "file.h" - and could not find ,so generate "fatal error: No such file" and preprocessor has been terminated. Therefore, next preprocessing templates and other has been stop. And therefore, I received invalid declaration.

    I found fixing: -Need will doing that preprocessor not terminate via "fatal error: No such file".

    I changed the code (I added the construction to the custom ParseDeclarationAction class, which is inherited from ASTFrontendAction):

    CI.getPreprocessor().SetSuppressIncludeNotFoundError(true);

    In result I have class:

    class ParseDeclarationAction : public ASTFrontendAction { public: virtual unique_ptr CreateASTConsumer(CompilerInstance &CI, StringRef InFile) { CI.getPreprocessor().SetSuppressIncludeNotFoundError(true); return unique_ptr(new ParseDeclarationConsumer(&CI.getASTContext())); } };

    I think may problem will be help other clang users.

    This task is resolved.

    Best Regards, Ivan.