[llvm-bugs] [Bug 42651] New: noreturn attributes prevent template function pointer arguments from working

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Jul 17 05:24:48 PDT 2019


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

            Bug ID: 42651
           Summary: noreturn attributes prevent template function pointer
                    arguments from working
           Product: clang
           Version: 8.0
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: js at alien8.de
                CC: blitzrakete at gmail.com, dgregor at apple.com,
                    erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
                    richard-llvm at metafoo.co.uk

I'm working on a piece of code that has template functions specialized on
function pointers. These pointers usually point to functions declared noreturn.
This generally works with gcc, but fails with clang due to errors like:

% clang++ -std=c++11 -c syscall.cpp
syscall.cpp:8:7: error: address of overloaded function 'send_msg' cannot be
static_cast to type 'void (*)()'
  d ? static_cast<void (*)()>(send_msg<b>) : nullptr;
      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
syscall.cpp:6:27: note: candidate function template
template <void()> void a::send_msg() {
                          ^
syscall.cpp:10:18: error: explicit instantiation of 'send_msg' does not refer
to a function template, variable
      template, member function, member class, or static data member
template void a::send_msg<a::c>();
                 ^
syscall.cpp:6:27: note: candidate template ignored: invalid
explicitly-specified argument for 1st template parameter
template <void()> void a::send_msg() {
                          ^
2 errors generated.

creduce reduced the problem to this:

```
class a {
  __attribute__((noreturn)) static void b();
  __attribute__((noreturn)) static void c();
  template <void()> static void send_msg();
};
template <void()> void a::send_msg() {
  int d;
  d ? static_cast<void (*)()>(send_msg<b>) : nullptr;
}
template void a::send_msg<a::c>();
```

Removing the noreturn attributes works around the problem.

-- 
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/20190717/da610018/attachment.html>


More information about the llvm-bugs mailing list