0

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?

2 Answers2

0

There is a difference between partial specialization and default arguments. Partial specialization creates a different version of the code for different template parameters, where default arguments provide the template parameters when not specialized.

I believe you can still mix them and get the code you want:

template < class T> class TYPE_A { };

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

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

typedef TYPE_B<double> B_Test;

The B_Test class should still use the specialization where the second parameter is `TYPE_A

tarkmeper
  • 767
  • 3
  • 12
0

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.