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

Masoud Ataei via cfe-dev cfe-dev at lists.llvm.org
Wed Jun 14 09:43:02 PDT 2017


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.)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20170614/c86f9052/attachment.html>


More information about the cfe-dev mailing list