[cfe-dev] Template class: initialization list and overloaded functions
Eli Friedman
eli.friedman at gmail.com
Tue Sep 25 12:44:39 PDT 2012
On Tue, Sep 25, 2012 at 10:06 AM, Yin Qiu <qiuyin at gmail.com> wrote:
> Hi,
>
> I noticed some discrepancy when I used libclang to parse a template class definition and a plain non-template one.
>
> Here's the code I fed clang:
> 1 struct A
> 2 {
> 3 A(int);
> 4 };
> 5
> 6 struct Bar
> 7 {
> 8 Bar(int);
> 9
> 10 void go();
> 11 void go(int);
> 12 };
> 13
> 14 template <class T>
> 15 struct Foo : public Bar
> 16 {
> 17 Foo()
> 18 : Bar(3), a(0)
> 19 {}
> 20
> 21 void baz()
> 22 {
> 23 go();
> 24 }
> 25
> 26 A a;
> 27 };
> 28
> 29 struct Oof : public Bar
> 30 {
> 31 Oof()
> 32 : Bar(3), a(0)
> 33 {}
> 34
> 35 void baz()
> 36 {
> 37 go();
> 38 }
> 39
> 40 A a;
> 41 };
>
> Classes Foo and Oof essentially have the same piece of code except that the former is a class template. clang_visitChildren() shows some differences when parsing the two.
>
> Line 18 vs. Line 32:
> clang reported two UnexposedExpr's at line 18 for those two expressions in the initialization list; whereas it reports two CallExpr's (ctor invocations) at line 32. Can we expose those CallExpr's in the initialization list of a class template as well?
>
> Line 23 vs. Line 37:
> For both classes, a CallExpr and a MemberRefExpr are reported. But for Foo<T>, there is an additional OverloadedDeclRef. Although Bar::go() has two overloads, isn't the function resolved already when we say go() (with void argument) in Foo<T>::baz()?
>
> Did I miss something? Please advise. Thanks!
The API is just reflecting the AST, and trying to aggressively build
more resolved expressions in templates hasn't really been a priority.
If you're interested, patches welcome.
-Eli
More information about the cfe-dev
mailing list