Casting.h:51:16: error: no member named 'classof' in 'clang::ArrayTypeLoc'

To avoid reporting an already-fixed issue for a trap that occurs in some AST internals when I run some ASTvisitor code, I’ve updated to a current version of the compiler (Revision: 175922). Unfortunately this breaks my visitor source in a way that I’m not sure how to deal with:

In file included from /clangdir/include/clang/AST/RecursiveASTVisitor.h:17:
In file included from /clangdir/include/clang/AST/Decl.h:17:
In file included from /clangdir/include/clang/AST/APValue.h:17:
In file included from /clangdir/include/clang/Basic/LLVM.h:22:
/clangdir/include/llvm/Support/Casting.h:51:16: error: no member named ‘classof’ in ‘clang::ArrayTypeLoc’
return To::classof(&Val);

/clangdir/include/llvm/Support/Casting.h:80:32: note: in instantiation of member function 'llvm::isa_impl<clang::ArrayTypeLoc, clang::TypeLoc,
>::doit' requested here
return isa_impl<To, From>::doit(*Val);
^
/clangdir/include/llvm/Support/Casting.h:113:36: note: in instantiation of member function 'llvm::isa_impl_cl<clang::ArrayTypeLoc,
clang::TypeLoc *>::doit' requested here
return isa_impl_cl<To,FromTy>::doit(Val);
^
/clangdir/include/llvm/Support/Casting.h:124:70: note: in instantiation of member function 'llvm::isa_impl_wrap<clang::ArrayTypeLoc,
clang::TypeLoc *, clang::TypeLoc *>::doit' requested here
return isa_impl_wrap<X, Y, typename simplify_type<Y>::SimpleType>::doit(Val);
^
/clangdir/include/llvm/Support/Casting.h:276:10: note: in instantiation of function template specialization
'llvm::isa<clang::ArrayTypeLoc, clang::TypeLoc *>' requested here
return isa<X>(Val) ? cast<X>(Val) : 0;
^
./classvisitor.h:69:51: note: in instantiation of function template specialization 'llvm::dyn_cast<clang::ArrayTypeLoc, clang::TypeLoc>' requested here
if ( const ArrayTypeLoc * pTypeLocIfArray = dyn_cast<ArrayTypeLoc>( &thisFieldTypeLoc ) )
^

The code in question is:

inline QualType getQualTypeForDecl( DeclaratorDecl * f )
{
TypeSourceInfo * pThisFieldSourceInfo = f->getTypeSourceInfo() ;

TypeLoc thisFieldTypeLoc = pThisFieldSourceInfo->getTypeLoc() ;

// don't care if it's an array, just want the basic underlying type of the array.
for ( ; ; )
{
if ( const ArrayTypeLoc * pTypeLocIfArray = dyn_cast<ArrayTypeLoc>( &thisFieldTypeLoc ) )
{
thisFieldTypeLoc = pTypeLocIfArray->getElementLoc() ;
}
else
{
break ;
}
}

return thisFieldTypeLoc.getType() ;
}

which was a helper function I used to extract the underlying type in case it was an array. I'm assuming that this should now be done differently... if so, how?

See commit r175462.

Dmitri

To avoid reporting an already-fixed issue for a trap that occurs in some
AST internals when I run some ASTvisitor code, I've updated to a current
version of the compiler (Revision: 175922). Unfortunately this breaks my
visitor source in a way that I'm not sure how to deal with:

In file included from /clangdir/include/clang/AST/RecursiveASTVisitor.h:17:
In file included from /clangdir/include/clang/AST/Decl.h:17:
In file included from /clangdir/include/clang/AST/APValue.h:17:
In file included from /clangdir/include/clang/Basic/LLVM.h:22:
/clangdir/include/llvm/Support/Casting.h:51:16: error: no member named
'classof' in 'clang::ArrayTypeLoc'
    return To::classof(&Val);
           ~~~~^
/clangdir/include/llvm/Support/Casting.h:80:32: note: in instantiation of
member function 'llvm::isa_impl<clang::ArrayTypeLoc, clang::TypeLoc,
      >::doit' requested here
    return isa_impl<To, From>::doit(*Val);
                               ^
/clangdir/include/llvm/Support/Casting.h:113:36: note: in instantiation of
member function 'llvm::isa_impl_cl<clang::ArrayTypeLoc,
      clang::TypeLoc *>::doit' requested here
    return isa_impl_cl<To,FromTy>::doit(Val);
                                   ^
/clangdir/include/llvm/Support/Casting.h:124:70: note: in instantiation of
member function 'llvm::isa_impl_wrap<clang::ArrayTypeLoc,
      clang::TypeLoc *, clang::TypeLoc *>::doit' requested here
  return isa_impl_wrap<X, Y, typename
simplify_type<Y>::SimpleType>::doit(Val);
                                                                     ^
/clangdir/include/llvm/Support/Casting.h:276:10: note: in instantiation of
function template specialization
      'llvm::isa<clang::ArrayTypeLoc, clang::TypeLoc *>' requested here
  return isa<X>(Val) ? cast<X>(Val) : 0;
         ^
./classvisitor.h:69:51: note: in instantiation of function template
specialization 'llvm::dyn_cast<clang::ArrayTypeLoc, clang::TypeLoc>'
requested here
      if ( const ArrayTypeLoc * pTypeLocIfArray = dyn_cast<ArrayTypeLoc>(
&thisFieldTypeLoc ) )
                                                  ^

The code in question is:

inline QualType getQualTypeForDecl( DeclaratorDecl * f )
{
   TypeSourceInfo * pThisFieldSourceInfo = f->getTypeSourceInfo() ;

   TypeLoc thisFieldTypeLoc = pThisFieldSourceInfo->getTypeLoc() ;

   // don't care if it's an array, just want the basic underlying type of
the array.
   for ( ; ; )
   {
      if ( const ArrayTypeLoc * pTypeLocIfArray = dyn_cast<ArrayTypeLoc>(
&thisFieldTypeLoc ) )

See 175462 for the change that broke this & contains all the cleanup for
this change (so lots of examples)

You should rewrite this code as:

if (ArrayTypeLoc TypeLocIfArray = thisFieldTypeLoc.getAs<ArrayTypeLoc>())

As per another thread on cfe-commits, this may change in the future to:

if (Optional<ArrayTypeLoc> TypeLocIfArray =
thisFieldTypeLoc.getAs<ArrayTypeLoc>())

Hope that helps.

- David

Please add this change to docs/ReleaseNotes.rst under "Internal API
Changes" (and reference r175462) . Thanks!

-- Sean Silva

Thanks for the reminder/request.

r175970 & r175971

Cool, thanks.

-- Sean Silva