[cfe-dev] Function Arg Type not expected
don hinton via cfe-dev
cfe-dev at lists.llvm.org
Wed Jun 15 19:29:23 PDT 2016
If you dump the ast, -Xclang -ast-dump -fsyntax-only, you'll see that when
s is passed by value, an ImplicitCastExpr node is created for the implicit
type conversion from "struct S<int>" to "const struct S<int>", and you are
ignoring implicits, IgnoreImplicit():
|-CallExpr 0x7fefab076990 <line:44:3, col:9> 'void'
| |-ImplicitCastExpr 0x7fefab076978 <col:3> 'void (*)(struct S<int>)'
<FunctionToPointerDecay>
| | `-DeclRefExpr 0x7fefab0768e8 <col:3> 'void (struct S<int>)' lvalue
Function 0x7fefab0767e0 'Func' 'void (struct S<int>)' (FunctionTemplate
0x7fefab06e808 'Func')
| `-CXXConstructExpr 0x7fefab076a28 <col:8> 'struct S<int>':'struct
S<int>' 'void (const struct S<int> &) throw()'
| `-ImplicitCastExpr 0x7fefab0769c0 <col:8> 'const struct S<int>'
lvalue <NoOp>
| `-DeclRefExpr 0x7fefab0765b8 <col:8> 'S<int>':'struct S<int>'
lvalue Var 0x7fefab06ee48 's' 'S<int>':'struct S<int>'
If you made s const instead, i.e., const S<int> s, then clang wouldn't need
to implicitly convert it and you should see it.
hth...
don
On Wed, Jun 15, 2016 at 5:21 PM, Daniel Dilts via cfe-dev <
cfe-dev at lists.llvm.org> wrote:
> I am writing a tool using the 3.8.0 source code. My ASTMatcher is
> callExpr().bind("callExpr"); I am getting the type of the first argument
> with auto type = callExpr->getArg(i)->IgnoreImplicit()->getType();
>
> Given this code:
>
> template <typename>
> struct S{};
>
> void Func2()
> {
> S<int> s;
> Func(s);
> }
>
> If Func is declared as either of these, then
> type->getAs<TemplateSpecializationType>() returns a non-null value and
> type.getAsString() returns "S<int>":
>
> void Func(...);
>
> template <typename T>
> void Func(const T&);
>
> If Func is declared as this, then
> type->getAs<TemplateSpecializationType>() returns null and
> type.getAsString() returns "struct S<int>":
>
> template <typename T>
> void Func(T);
>
>
>
> I would expect all three to return a non-null value and the same result
> from getAsString. Why do these differ?
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20160615/c2a0ae4b/attachment.html>
More information about the cfe-dev
mailing list