[llvm-bugs] [Bug 49520] New: Erroneous template deduction
via llvm-bugs
llvm-bugs at lists.llvm.org
Wed Mar 10 11:22:03 PST 2021
https://bugs.llvm.org/show_bug.cgi?id=49520
Bug ID: 49520
Summary: Erroneous template deduction
Product: clang
Version: unspecified
Hardware: PC
OS: Linux
Status: NEW
Severity: normal
Priority: P
Component: C++
Assignee: unassignedclangbugs at nondot.org
Reporter: ColinMacLean at lbl.gov
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 discovered a bug in Clang's template argument deduction while working on
array support for a pointer wrapping class. This incorrect behavior can be
simplified into the following reproducer:
#include <type_traits>
template<typename T>
struct A {};
template<typename T>
struct A<T[]> : A<T> {};
template<typename T>
void foo(T* a, A<T>& b) {}
template<typename T>
void bar(T* a, A<std::type_identity_t<T>>& b) {}
void test()
{
int * t1;
A<int> t2;
A<int[]> t3;
foo(t1,t2);
foo(t1,t3); // GCC: correctly errors on conflicting deductions for T: int
and int[]
// Clang: Erroneously performs implicit cast, which should only
be allowed
// after a successful template deduction
bar(t1,t2);
bar(t1,t3); // Compliant implicit cast for second argument.
}
In the case of the function foo(), the deduction should try to deduce to both
int and int[] simultaneously with the parameters t1 and t3 and fail due to
being different types. Godbolt shows T is deduced to int on Clang.
std::type_identity_t<T> should be necessary to establish a non-deduced context
if implicit conversion to A<int> is desired. This implicit conversion should
only happen after a template deduction is successful.
This bug affects all known Clang versions, tested from 3.0 to trunk with
Godbolt. It also affects all C++ standard options used from C++98 to C++2a.
--
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/20210310/7b17b1e6/attachment.html>
More information about the llvm-bugs
mailing list