In LLVM10, this code is ok
std::string StringName = ErrorTypeVarDecl->getName();
but update to LLVM15,my code show some error as follow
error: conversion from ‘llvm::StringRef’ to non-scalar type ‘std::__cxx11::string {aka std::__cxx11::basic_string<char>}’ requested
std::string StringName = ErrorTypeVarDecl->getName();
I am confused, please help me.
after change the code as follow, error disappear
std::string StringName = ErrorTypeVarDecl->getName().str();
llvm 11 included this change [ADT] Make StringRef's std::string conversion operator explicit · llvm/llvm-project@777180a · GitHub, which is still present in 15. This made the conversion to std::string explicit.
So you must now ask for it,. as shown in [ADT] Make StringRef's std::string conversion operator explicit · llvm/llvm-project@777180a · GitHub where they updated all the uses in llvm.
In your case:
std::string StringName = std::string(ErrorTypeVarDecl->getName());
Or stick with .str()
, same result.
get it .thanks for your reply.