[cfe-dev] Use of deleted function std::unique_ptr

陳韋任 via cfe-dev cfe-dev at lists.llvm.org
Wed Jun 14 15:20:29 PDT 2017


Probably you can `grep -r "EnterTokenStream" lib/*` to see how pass
unique_ptr to
EnterTokenStream. Seem you need to use std::move.

HTH,
chenwj


2017-06-15 0:43 GMT+08:00 Masoud Ataei via cfe-dev <cfe-dev at lists.llvm.org>:

> Hello all,
>
> I have the following lines of code. To run it, I need to change the rule
> of the function "EnterTokenStream" from private to a public function
> in "/usr/local/include/clang/Lex/Preprocessor.h". In this case this code
> will working with raw pointer "*Toks".
> ------------------------------------
> PP.Lex(Tok);
> SmallVector<Token, 4> Pragma;
> Pragma.push_back(Tok);
>
> Token *Toks = new Token[Pragma.size()];
> std::copy(Pragma.begin(), Pragma.end(), Toks);
> PP.EnterTokenStream(Toks, Pragma.size(), true, true);
> --------------------------------------------------------------
>
> But default rule for the function "EnterTokenStream" is private. So I
> cannot call this function, and I should call this one:
> ---------------------------------------------
> void EnterTokenStream(std::unique_ptr<Token[]> Toks, unsigned NumToks,
> bool DisableMacroExpansion)
> ---------------------------------------------
>
>
> First argument of this function needs  "std::unique_ptr<Token[]> Toks". So
> I have tried to define Toks as a unique pointer. I did like this:
> --------------------------------------------
> PP.Lex(Tok);
> SmallVector<Token, 4> Pragma;
> Pragma.push_back(Tok);
>
> unique_ptr<Token[]> Toks(new Token[Pragma.size()]);
> std::copy(Pragma.begin(), Pragma.end(), Toks);
> PP.EnterTokenStream(Toks, Pragma.size(), true);
> ------------------------------------------------
>
> but it gives me the following error for std::copy:
> ---------------------------------------------
>  error: use of deleted function ‘std::unique_ptr<_Tp [],
> _Dp>::unique_ptr(const std::unique_ptr<_Tp [], _Dp>&) [with _Tp =
> clang::Token; _Dp = std::default_delete<clang::Token []>]’
>     std::copy(Pragma.begin(), Pragma.end(), Toks);
> ----------------------------------------------------------
>
> and the same error for EnterTokenStream:
> ------------------------------------------------------
> error: use of deleted function ‘std::unique_ptr<_Tp [],
> _Dp>::unique_ptr(const std::unique_ptr<_Tp [], _Dp>&) [with _Tp =
> clang::Token; _Dp = std::default_delete<clang::Token []>]’
>     PP.EnterTokenStream(Toks, Pragma.size(), true);
> ------------------------------------------------------------
>
> Can anyone help me how to fix this errors? How can I change my original
> code to something that I can use the new EnterTokenStream function?
>
> Thank you.
>
> --
> ------
> ----------
> Masoud Ataei (Mr.)
>
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>
>


-- 
Wei-Ren Chen (陳韋任)
Homepage: https://people.cs.nctu.edu.tw/~chenwj
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20170615/f0a78126/attachment.html>


More information about the cfe-dev mailing list