[LLVMbugs] [Bug 13682] New: Templates are not instantiated prior to determining an overload set

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Thu Aug 23 13:53:26 PDT 2012


http://llvm.org/bugs/show_bug.cgi?id=13682

             Bug #: 13682
           Summary: Templates are not instantiated prior to determining an
                    overload set
           Product: clang
           Version: 3.1
          Platform: PC
        OS/Version: Windows XP
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++11
        AssignedTo: unassignedclangbugs at nondot.org
        ReportedBy: rivorus_katarni at yahoo.com
                CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
    Classification: Unclassified


I've looked through [basic.lookup.argdep] and I'm not 100% positive if this is
a bug or if it's "expected" standard behavior. Here is a simple test case:

////////////////////
template< class > struct foo;

namespace adl {

struct foo_base {};

int bar( foo< void > const& );

}

template< class > struct foo : adl::foo_base {};

extern foo< void > instance_of_foo; // Remove "extern" for this to succeed

// Clang produces an error here since foo< void > isn't instantiated (it's left
// incomplete). Is this expected behavior or is it a Clang bug?
int this_fails_in_clang = sizeof( bar( instance_of_foo ) );
////////////////////

To be clear on what I consider the problem -- when producing an overload set
from an unqualified name and a set of arguments, if one or more of the
arguments is a template specialization, Clang (apparently) does not first make
sure that the type is instantiated, if possible. Because of this, if the type
is left incomplete, it may miss certain overloads that could exist in the
namespace of base classes or in friend functions inlined in the class
definition (though the latter seems to work in Clang, as I would expect, but is
inconsistent with the above behavior).

This may seem like a rare situation, but it actually came up in production code
when using std::declval to determine the existence/result type of an associated
function. Since the template was not instantiated before hand, the overload
lookup failed. There is a workaround for users that is easy enough -- manually
instantiate the template in any number of ways prior to doing the unqualified
call -- but intuitively this seems as though it should be unnecessary and I'm
not clear enough on standard-speak to verify that it is incorrect to begin
with.

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list