[llvm-bugs] [Bug 28683] New: clang fails to properly handle a certain template definition involving pointers to member functions

via llvm-bugs llvm-bugs at lists.llvm.org
Sun Jul 24 04:22:39 PDT 2016


https://llvm.org/bugs/show_bug.cgi?id=28683

            Bug ID: 28683
           Summary: clang fails to properly handle a certain template
                    definition involving pointers to member functions
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++11
          Assignee: unassignedclangbugs at nondot.org
          Reporter: beck.ct at gmail.com
                CC: dgregor at apple.com, llvm-bugs at lists.llvm.org
    Classification: Unclassified

Clang trunk reports an error when compiling the following simple program:

==============

template <typename T, typename... Args>
using member_callback_t = int (T::*)(void *, Args...);

template <typename T, T t> struct dispatch_helper;

template <typename T, typename ... Args, member_callback_t<T, Args...>
target_func>
struct dispatch_helper<member_callback_t<T, Args...>, target_func> {
  static int dispatch(void *) { return 0; }
};

#define DISPATCH(F) &dispatch_helper<decltype(F), (F)>::dispatch

struct test {
  int callback_one(void *, int) { return 0; }
};

typedef int (*desired_sig_t)(void *);

int main() {
  desired_sig_t ptr{DISPATCH(&test::callback_one)};
}

==============

main.cpp:20:21: error: implicit instantiation of undefined template
      'dispatch_helper<int (test::*)(void *, int), &test::callback_one>'
  desired_sig_t ptr{DISPATCH(&test::callback_one)};
                    ^
main.cpp:11:22: note: expanded from macro 'DISPATCH'
#define DISPATCH(F) &dispatch_helper<decltype(F), (F)>::dispatch
                     ^
main.cpp:4:35: note: template is declared here
template <typename T, T t> struct dispatch_helper;
                                  ^
1 error generated.

==============

This code must be compiled with `-std=c++11`.

Both GCC and MSVC 2015 accept this program.

In every released version of clang up to and including 3.9, this code would
cause an internal compiler error, see this earlier bug report from 6 months
ago: https://llvm.org/bugs/show_bug.cgi?id=26586

I'm glad to see that it no longer crashes, but I think the error is not the
correct behavior and clang should accept and compile the program.

-- 
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/20160724/98bd6d70/attachment.html>


More information about the llvm-bugs mailing list