[LLVMbugs] [Bug 17030] New: Clang in C++11 mode refuses to get address of templated function as template parameter

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Wed Aug 28 16:35:16 PDT 2013


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

            Bug ID: 17030
           Summary: Clang in C++11 mode refuses to get address of
                    templated function as template parameter
           Product: clang
           Version: 3.1
          Hardware: PC
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++11
          Assignee: unassignedclangbugs at nondot.org
          Reporter: felixcca at yahoo.ca
                CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
    Classification: Unclassified

Apple's Clang that ships with Xcode 4.6.3 fails to parse the following program:

    template<void (*F)(void)>
    struct Func {};

    template<typename T>
    void foo();

    int main() {
        struct Bar {}; // function-local type
        Func<foo<Bar>> x;
    }

The error is the following, on the line that declares `x` in `main`:

> error: non-template argument refers to function 'foo<Bar>' with internal linkage
> Func<foo<Bar>> x;
>      ^~~~~~~~

I might be mistaken as I'm not very familiar with linkage, but this seems to
run afoul of n3242's ยง14.3.2:

> A template-argument for a non-type, non-template template-parameter shall be one of:
> [...]
> - a constant expression (5.19) that designates the address of an object with static storage duration and external or internal linkage or __a function with external or internal linkage__, including function templates and function template-ids but excluding non-static class members [...]

It also happens (according to this guy: http://stackoverflow.com/q/18498957/)
with Clang 3.4 (trunk 187493), although in this case it says the function "has
no linkage" (which seems to be a better reason to refuse it).

G++ will gladly compile that code.

It should also be noted that this works with clang:

    template<typename T>
    void foo();

    int main() {
        struct Bar {}; // function-local type
        void (*y)() = foo<Bar>;
    }

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20130828/cb23c5b5/attachment.html>


More information about the llvm-bugs mailing list