<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Template<Function> - Definition with same mangled name error when Function attributes differ"
   href="https://bugs.llvm.org/show_bug.cgi?id=39860">39860</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Template<Function> - Definition with same mangled name error when Function attributes differ
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>-New Bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>kobalicek.petr@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>htmldeveloper@gmail.com, llvm-bugs@lists.llvm.org, neeilans@live.com, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>The following snippet fails when compiled in 32-bit mode (-m32):

#include <stdint.h>

#if defined(_MSC_VER)
  #define FASTCALL __fastcall
#else
  #define FASTCALL __attribute((fastcall))
#endif

int f(int x) { return x; }
int FASTCALL g(int x) { return x; }

template<typename Fn>
static intptr_t func_as_ptr(Fn fn) { return intptr_t(fn); }

intptr_t fAsPtr() { return func_as_ptr(f); }
intptr_t gAsPtr() { return func_as_ptr(g); }

This may be a duplicate of #28909 although it's a bit different test-case and
I'm not sure this can be workarounded by using C++ attributes. GCC and MSVC
pass this test-case.

Compiler Explorer:

<a href="https://godbolt.org/#g:!((g:!((g:!((h:codeEditor,i:(j:1,lang:c%2B%2B,source:'%23include+%3Cstdint.h%3E%0A%0A%23if+defined(_MSC_VER)%0A%23+define+FASTCALL+__fastcall%0A%23else%0A%23+define+FASTCALL+__attribute((fastcall))%0A%23endif%0A%0Aint+f(int+x)+%7B+return+x%3B+%7D%0Aint+FASTCALL+g(int+x)+%7B+return+x%3B+%7D%0A%0Atemplate%3Ctypename+Fn%3E%0Astatic+intptr_t+func_as_ptr(Fn+fn)+%7B%0A++return+intptr_t(fn)%3B%0A%7D%0A%0Aintptr_t+fAsPtr()+%7B%0A++return+func_as_ptr(f)%3B%0A%7D%0A%0Aintptr_t+gAsPtr()+%7B%0A++return+func_as_ptr(g)%3B%0A%7D%0A'),l:'5',n:'0',o:'C%2B%2B+source+%231',t:'0')),k:28.292682926829272,l:'4',n:'0',o:'',s:0,t:'0'),(g:!((h:compiler,i:(compiler:clang_trunk,filters:(b:'0',binary:'1',commentOnly:'0',demangle:'0',directives:'0',execute:'1',intel:'0',trim:'1'),lang:c%2B%2B,libs:!(),options:'-O2+-m32',source:1),l:'5',n:'0',o:'x86-64+clang+(trunk)+(Editor+%231,+Compiler+%231)+C%2B%2B',t:'0')),k:18.125901244232036,l:'4',n:'0',o:'',s:0,t:'0'),(g:!((h:compiler,i:(compiler:gsnapshot,filters:(b:'0',binary:'1',commentOnly:'0',demangle:'0',directives:'0',execute:'1',intel:'0',trim:'1'),lang:c%2B%2B,libs:!(),options:'-O2+-m32',source:1),l:'5',n:'0',o:'x86-64+gcc+(trunk)+(Editor+%231,+Compiler+%232)+C%2B%2B',t:'0')),k:18.00384130319344,l:'4',n:'0',o:'',s:0,t:'0'),(g:!((h:compiler,i:(compiler:'vcpp_v19_15_(vs_15_8)_x86',filters:(b:'0',binary:'1',commentOnly:'0',demangle:'0',directives:'0',execute:'1',intel:'0',trim:'1'),lang:c%2B%2B,libs:!(),options:/Ox,source:1),l:'5',n:'0',o:'x86+msvc+v19.15+(VS+15.8)+(Editor+%231,+Compiler+%233)+C%2B%2B',t:'0')),k:15.577574525745257,l:'4',n:'0',o:'',s:0,t:'0'),(g:!((h:output,i:(compiler:1,editor:1,wrap:'1'),l:'5',n:'0',o:'%231+with+x86-64+clang+(trunk)',t:'0')),k:20,l:'4',n:'0',o:'',s:0,t:'0')),l:'2',n:'0',o:'',t:'0')),version:4">https://godbolt.org/#g:!((g:!((g:!((h:codeEditor,i:(j:1,lang:c%2B%2B,source:'%23include+%3Cstdint.h%3E%0A%0A%23if+defined(_MSC_VER)%0A%23+define+FASTCALL+__fastcall%0A%23else%0A%23+define+FASTCALL+__attribute((fastcall))%0A%23endif%0A%0Aint+f(int+x)+%7B+return+x%3B+%7D%0Aint+FASTCALL+g(int+x)+%7B+return+x%3B+%7D%0A%0Atemplate%3Ctypename+Fn%3E%0Astatic+intptr_t+func_as_ptr(Fn+fn)+%7B%0A++return+intptr_t(fn)%3B%0A%7D%0A%0Aintptr_t+fAsPtr()+%7B%0A++return+func_as_ptr(f)%3B%0A%7D%0A%0Aintptr_t+gAsPtr()+%7B%0A++return+func_as_ptr(g)%3B%0A%7D%0A'),l:'5',n:'0',o:'C%2B%2B+source+%231',t:'0')),k:28.292682926829272,l:'4',n:'0',o:'',s:0,t:'0'),(g:!((h:compiler,i:(compiler:clang_trunk,filters:(b:'0',binary:'1',commentOnly:'0',demangle:'0',directives:'0',execute:'1',intel:'0',trim:'1'),lang:c%2B%2B,libs:!(),options:'-O2+-m32',source:1),l:'5',n:'0',o:'x86-64+clang+(trunk)+(Editor+%231,+Compiler+%231)+C%2B%2B',t:'0')),k:18.125901244232036,l:'4',n:'0',o:'',s:0,t:'0'),(g:!((h:compiler,i:(compiler:gsnapshot,filters:(b:'0',binary:'1',commentOnly:'0',demangle:'0',directives:'0',execute:'1',intel:'0',trim:'1'),lang:c%2B%2B,libs:!(),options:'-O2+-m32',source:1),l:'5',n:'0',o:'x86-64+gcc+(trunk)+(Editor+%231,+Compiler+%232)+C%2B%2B',t:'0')),k:18.00384130319344,l:'4',n:'0',o:'',s:0,t:'0'),(g:!((h:compiler,i:(compiler:'vcpp_v19_15_(vs_15_8)_x86',filters:(b:'0',binary:'1',commentOnly:'0',demangle:'0',directives:'0',execute:'1',intel:'0',trim:'1'),lang:c%2B%2B,libs:!(),options:/Ox,source:1),l:'5',n:'0',o:'x86+msvc+v19.15+(VS+15.8)+(Editor+%231,+Compiler+%233)+C%2B%2B',t:'0')),k:15.577574525745257,l:'4',n:'0',o:'',s:0,t:'0'),(g:!((h:output,i:(compiler:1,editor:1,wrap:'1'),l:'5',n:'0',o:'%231+with+x86-64+clang+(trunk)',t:'0')),k:20,l:'4',n:'0',o:'',s:0,t:'0')),l:'2',n:'0',o:'',t:'0')),version:4</a></pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>