<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 class's template friend inline function (with definition) with dependent template argument incorrectly treated as independent of class template due to indirect type access"
href="https://bugs.llvm.org/show_bug.cgi?id=44402">44402</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>template class's template friend inline function (with definition) with dependent template argument incorrectly treated as independent of class template due to indirect type access
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>All
</td>
</tr>
<tr>
<th>OS</th>
<td>All
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</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>davidfink314@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>Code (compile with -std=c++2a):
#include <type_traits>
#define OPT 0
template <bool B>
struct Foo {
template <typename U>
static constexpr bool isThis = std::is_same_v<Foo, U>;
#if OPT == 0
template <typename U>
using WhenThis = std::enable_if_t<isThis<U>, bool>;
#elif OPT == 1
template <typename U>
using WhenThis = std::enable_if_t<(B||!B)&&isThis<U>, bool>;
#else
template <typename U>
using WhenThis = std::enable_if_t<std::is_same_v<Foo, U>, bool>;
#endif
template <typename U, WhenThis<U> b>
friend constexpr void aha(U const & self) {}
};
template <typename T>
constexpr int failure(T const &) {
Foo<true> c;
aha<Foo<true>,false>(c);
return 1;
}
static_assert(failure(Foo<false>{}));
The issue: though OPT=0,1,2 should be identical, OPT=0 errors while the others
succeed:
<source>:21:27: error: redefinition of 'aha'
friend constexpr void aha(U const & self) {}
^
<source>:30:23: note: in instantiation of template class 'Foo<false>' requested
here
static_assert(failure(Foo<false>{}));
^
<source>:21:27: note: previous definition is here
friend constexpr void aha(U const & self) {}
Suspicion:
With OPT=1 or OPT=2, clang realizes (through use of B or Foo<B>) that WhenThis
depends on B. When instantiating the friend template function "aha", it puts
them in an overload set. With OPT=0, B/Foo<B> aren't directly used in WhenThis
- instead, Foo<B> is indirectly used via isThis, so clang treats the "aha"
definition differently, and two instantiations of class Foo result in a
redefinition error for "aha".</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>