Use of deleted function std::unique_ptr

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Use of deleted function std::unique_ptr

Xin Wang via cfe-dev
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
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Use of deleted function std::unique_ptr

Xin Wang via cfe-dev
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 <[hidden email]>:
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
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev




--
Wei-Ren Chen (陳韋任)
Homepage: https://people.cs.nctu.edu.tw/~chenwj

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Use of deleted function std::unique_ptr

Xin Wang via cfe-dev
Hello Chenwj,

Thank you for your reply. I did the following and it did work:

replace:
###
Token *Toks = new Token[Pragma.size()];
std::copy(Pragma.begin(), Pragma.end(), Toks);
PP.EnterTokenStream(Toks, Pragma.size(), /*DisableMacroExpansion=*/true, /*OwnsTokens=*/true);
##
by:
##
auto Toks = llvm::make_unique<Token[]>(Pragma.size());
Toks[0] = Pragma[0];Toks[1] = Pragma[1];Toks[2] = Pragma[2];Toks[3] = Pragma[3]; 
PP.EnterTokenStream(std::move(Toks), Pragma.size(), true); 
##

Bests

On Wed, Jun 14, 2017 at 6:20 PM, 陳韋任 <[hidden email]> wrote:
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 <[hidden email]>:
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
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev




--
Wei-Ren Chen (陳韋任)
Homepage: https://people.cs.nctu.edu.tw/~chenwj



--
------
----------
Masoud Ataei (Mr.)

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Use of deleted function std::unique_ptr

Xin Wang via cfe-dev
You can still use std::copy, but you'd need to pass Toks.get() as the last arg, instead of just 'Toks'.

On Wed, Jun 14, 2017 at 4:04 PM Masoud Ataei via cfe-dev <[hidden email]> wrote:
Hello Chenwj,

Thank you for your reply. I did the following and it did work:

replace:
###
Token *Toks = new Token[Pragma.size()];
std::copy(Pragma.begin(), Pragma.end(), Toks);
PP.EnterTokenStream(Toks, Pragma.size(), /*DisableMacroExpansion=*/true, /*OwnsTokens=*/true);
##
by:
##
auto Toks = llvm::make_unique<Token[]>(Pragma.size());
Toks[0] = Pragma[0];Toks[1] = Pragma[1];Toks[2] = Pragma[2];Toks[3] = Pragma[3]; 
PP.EnterTokenStream(std::move(Toks), Pragma.size(), true); 
##

Bests

On Wed, Jun 14, 2017 at 6:20 PM, 陳韋任 <[hidden email]> wrote:
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 <[hidden email]>:
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
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev




--
Wei-Ren Chen (陳韋任)
Homepage: https://people.cs.nctu.edu.tw/~chenwj



--
------
----------
Masoud Ataei (Mr.)
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Loading...