[LLVMbugs] [Bug 7425] New: function arguments which are const references fail to compile if they have a default value which is an instantiation of a template function

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Sun Jun 20 01:00:03 CDT 2010


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

           Summary: function arguments which are const references fail to
                    compile if they have a default value which is an
                    instantiation of a template function
           Product: clang
           Version: trunk
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: -New Bugs
        AssignedTo: unassignedclangbugs at nondot.org
        ReportedBy: josh.faust at gmail.com
                CC: llvmbugs at cs.uiuc.edu


llvm r106400
clang r106400

I don't know if this is valid C++ or not, but it compiles with gcc (4.4.3)

template<typename T>
void foo()
{
}

struct B
{
  template<typename T>
  B(const T&)
  {
  }
};

void bar(const B& b = foo<int>)
{
}

int main(int argc, char** argv)
{
  bar();
}


yields


test_clang.cpp:14:23: error: address of overloaded function 'foo' cannot be
converted to type 'B const'
void bar(const B& b = foo<int>)
                      ^
test_clang.cpp:14:19: note: passing argument to parameter 'b' here
void bar(const B& b = foo<int>)
                  ^
test_clang.cpp:20:3: error: no matching function for call to 'bar'
  bar();
  ^~~
test_clang.cpp:14:6: note: candidate function not viable: requires 1 argument,
but 0 were provided
void bar(const B& b = foo<int>)
     ^
2 errors generated.


Using:
void bar(B b = foo<int>);

works fine

The specific use case that fails in my codebase is with boost::function, e.g.:
void bar2(const boost::function<void()>& func = foo<int>);

-- 
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 LLVMbugs mailing list