[cfe-dev] Test argument for String literal
Aitor San Juan
aitor.sj at opendeusto.es
Thu May 1 04:37:33 PDT 2014
Sorry, I involuntarily sent the email without setting the subject.
2014-05-01 13:31 GMT+02:00 Aitor San Juan <aitor.sj at opendeusto.es>:
> Hello,
>
> In a checker I want to test whether an argument to a function call is a
> String literal, but I'm a bit stuck. Could anybody shed a bit of light on
> this?
>
> 1. This way seems to not work (although no compile-time error), but I
> don't understand why:
>
> const Expr *arg = CE->getArg(0); // CE is a CallExpr
> if ((arg != NULL) && (clang::isa<clang::StringLiteral>(arg))){
> ...
>
> 2. The following does not compile:
>
> const Expr *arg = CE->getArg(0); // CE is a CallExpr
> if (StringLiteral *SL = dyn_cast<StringLiteral>(arg)) {
>
> invalid conversion from ‘llvm::cast_retty<clang::StringLiteral, const
> clang::Expr*>::ret_type {aka const clang::StringLiteral*}’ to
> ‘clang::StringLiteral*’ [-fpermissive]
> if (StringLiteral *SL = dyn_cast<StringLiteral>(arg)) {
>
> ^
> 3. The following does not compile, however there's a non-const getArg()
> method:
>
> Expr *arg = CE->getArg(0); // CE is a CallExpr
> if (StringLiteral *SL = dyn_cast<StringLiteral>(arg)) {
>
> error: invalid conversion from ‘const clang::Expr*’ to ‘clang::Expr*’
> [-fpermissive]
> Expr *arg = CE->getArg(0);
> ^
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20140501/01a81bbd/attachment.html>
More information about the cfe-dev
mailing list