[cfe-dev] Function Instantiation: Where? Or is it?

Douglas Gregor dgregor at apple.com
Mon Jan 31 08:42:19 PST 2011


On Jan 31, 2011, at 8:12 AM, Larisse Voufo wrote:

> 
> Folks --
> 
> This has had me puzzled for a while, and I could use an answer asap.
> I am implementing concepts in Clang and seem to be missing a crucial piece of understanding, either of C++, or of Clang. 
> Basically, I have gotten mostly everything else implemented and working fine to the extend that I want them to, except for concept members instantiation (?).
> 
> Basic Example:  instantiation.cpp
> ----------------------
> 
> concept B<typename T> {
>   void f(int) { }
> }
> 
> concept_map B<int> {
>   void f(int) { }
> }
> 
> template<typename T>
> requires (B<T>) 
> void func(T a) {
> //    f(a);
>     f(0);
> }
> 
> int main(int argc, char **argv) 
> { 
>     int i=0;
>     func<int>(i); 
> }
> 
> Compilation:  clang++ instantiation.cpp -o example
> ----------------------
> It seems to be failing at link time, with the following error message:
> 
> Undefined symbols:
>   "__ZN1B1fEi", referenced from:
>       __Z4funcIiEvT_ in cc-MXLAc6.o
> ld: symbol(s) not found
> 
> 
> Any idea? Anyone? 
> 1) At which point are functions marked for instantiation?

Look for calls to Sema::MarkDeclarationReferenced throughout Sema.

> 2 ) At which point are they instantiated ?

At the end of the translation unit.

> 3) If instantiated, why would they not be visible by the linker? 

Probably because the template instantiation mechanism couldn't find the definition of B<int>::f(int).

	- Doug
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20110131/cf456d88/attachment.html>


More information about the cfe-dev mailing list