[cfe-dev] abort calling getTypeSize
Dmitri Gribenko
gribozavr at gmail.com
Sun Feb 24 15:00:05 PST 2013
On Mon, Feb 25, 2013 at 12:46 AM, Peeter Joot <peeter.joot at gmail.com> wrote:
> With the following sample code:
>
> template <class T, size_t extraSize >
> struct OSS_STRUCTURE_PAD_DELTA : public T
> {
> char pad[ extraSize ] ;
> } ;
>
> and an ast visitor that calls getTypeSize():
>
> bool VisitFieldDecl( FieldDecl * f )
> {
> RecordDecl * r = f->getParent() ;
> const QualType & theMembersClassType = m_context.getRecordType( r ) ;
>
> TypeSourceInfo * pThisFieldSourceInfo = f->getTypeSourceInfo() ;
>
> TypeLoc thisFieldTypeLoc = pThisFieldSourceInfo->getTypeLoc() ;
>
> const QualType & thisFieldQualType = thisFieldTypeLoc.getType() ;
>
> size_t szInBits = m_context.getTypeSize( thisFieldQualType ) ;
> size_t offsetInBits = m_context.getFieldOffset( f ) ;
>
> cout
> << "[" << offsetInBits/8 << "]:\t"
> << theMembersClassType.getAsString( m_pp ) << "::" <<
> thisFieldQualType.getAsString( m_pp ) << "\t" << f->getNameAsString()
> << "\tsize: " << szInBits/8 << endl ;
> ;
>
> return true ;
> }
>
> I get the following abort:
>
> t.C:5:20: error: unknown type name 'size_t'
> template <class T, size_t extraSize >
> ^
> Should not see dependent types
> UNREACHABLE executed at
> /home/hotellnx94/peeterj/clang/sources/llvm/tools/clang/lib/AST/ASTContext.cpp:1322!
It is by design. You can not compute a sizeof of a dependent type,
and type of 'pad' is value-dependent on 'extraSize'.
Dmitri
--
main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
(j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr at gmail.com>*/
More information about the cfe-dev
mailing list