[cfe-dev] Function Arg Type not expected

don hinton via cfe-dev cfe-dev at lists.llvm.org
Thu Jun 16 13:38:04 PDT 2016


Yes, you're correct -- I left out the const in my test.

Looks like it's because RecordTypes aren't sugared.  See Type.cpp line 317.

if (!Ty->isSugared()) return 0;

On Thu, Jun 16, 2016 at 8:57 AM, Daniel Dilts <diltsman at gmail.com> wrote:

> You are right that all it does have the implicit cast to const, but all
> three have an implicit cast to const that are notated as <NoOp>.  So, that
> doesn't appear to be what is causing my issues.
>
> On Wed, Jun 15, 2016 at 7:29 PM, don hinton <hintonda at gmail.com> wrote:
>
>> 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/20160616/1b88f3da/attachment.html>


More information about the cfe-dev mailing list