[cfe-dev] template issue with clang::RedeclarableTemplateDecl::SpecIterator

Kim Gräsman kim.grasman at gmail.com
Mon Nov 18 01:11:10 PST 2013


(necromancy alert)

On Thu, Feb 21, 2013 at 12:25 AM, Laszlo Nagy
<rizsotto.mailinglist at gmail.com> wrote:
>
> run into a weird error message when tried to compile a project...
>
> tools/clang/include/clang/AST/DeclTemplate.h:560:22: error:
>       no matching constructor for initialization of 'SetIteratorType' (aka
>       'FoldingSetVectorIterator<clang::FunctionTemplateSpecializationInfo,
>       typename SmallVector<FunctionTemplateSpecializationInfo *,
> 8>::iterator>')
>     SpecIterator() : SetIter() {}
>                      ^
> Actually the user of the code is wrong to default construct for the
> iterator. But I think it would be more elegant to not declare default
> construtor, if the parent class does not have it. Namely the
> llvm::FoldingSetVectorIterator class does not have, therefore the
> clang::RedeclarableTemplateDecl::SpecIterator should not have either.

I see this as well when I run IWYU on itself on Windows. Running
clang-check on the same code does not exhibit any problems.

The code in question:

--
    typedef typename llvm::FoldingSetVector<EntryType>::iterator
      SetIteratorType;

    SetIteratorType SetIter;

  public:
    SpecIterator() : SetIter() {}
    SpecIterator(SetIteratorType SetIter) : SetIter(SetIter) {}
--

llvm::FoldingSetVector<EntryType>::iterator does not have a default
constructor, so this is clearly invalid.

I think the problem might be that IWYU has some black magic to
instantiate templates to better detect uses, and the default
constructor is in fact otherwise unused.

Should the SpecIterator default constructor be removed? I'd be happy
to provide a patch if this seems like the right way forward.

Thanks,
- Kim



More information about the cfe-dev mailing list