[llvm-bugs] [Bug 44402] 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
via llvm-bugs
llvm-bugs at lists.llvm.org
Sun Dec 29 10:07:15 PST 2019
https://bugs.llvm.org/show_bug.cgi?id=44402
Bug ID: 44402
Summary: 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
Product: clang
Version: trunk
Hardware: All
OS: All
Status: NEW
Severity: normal
Priority: P
Component: -New Bugs
Assignee: unassignedclangbugs at nondot.org
Reporter: davidfink314 at gmail.com
CC: htmldeveloper at gmail.com, llvm-bugs at lists.llvm.org,
neeilans at live.com, richard-llvm at metafoo.co.uk
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".
--
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/20191229/4b1849e4/attachment-0001.html>
More information about the llvm-bugs
mailing list