public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/103333] New: [accepts-invalid] function template argument deduction for incompatible 'transformed A' / 'deduced A' pair
@ 2021-11-19 16:12 davveston at gmail dot com
2021-11-22 18:15 ` [Bug c++/103333] " leni536 at gmail dot com
0 siblings, 1 reply; 2+ messages in thread
From: davveston at gmail dot com @ 2021-11-19 16:12 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103333
Bug ID: 103333
Summary: [accepts-invalid] function template argument deduction
for incompatible 'transformed A' / 'deduced A' pair
Product: gcc
Version: 12.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: davveston at gmail dot com
Target Milestone: ---
The following program is accepted by GCC but rejected by Clang/MSVC
(-std=c++20):
---
#include <type_traits>
template<typename T, bool b>
struct S{
S() = default;
template<bool sfinae = true,
typename = std::enable_if_t<sfinae && !std::is_const<T>::value>>
operator S<T const, b>() { return S<T const, b>{}; }
};
template<typename T, bool b1, bool b2>
void f(S<const std::type_identity_t<T>, b1>,
// ^- T in non-deduced context for func-param
#1
S<T, b2>)
// ^- T deduced from here
{}
int main() {
S<int, true> s1{};
S<int, false> s2{};
f(s1, s2);
}
---
The program is ill-formed as function template argument deduction
([temp.deduct.call]) for the first argument resolves in a mismatched deduced A
vs. transformed A that is S<const int, true> and S<int, true>, respectively,
and none of the three special cases of [temp.deduct.call]/4 allows this
mismatch.
[temp.arg.explicit]/7 allows a function argument to be converted to the type of
the corresponding function parameter, but only if the parameter type contains
to template arguments that participate in template argument deduction [from
that function argument]. This does not apply here, as the non-type template
parameter 'b1' participates in template argument deduction for the call.
---
https://timsong-cpp.github.io/cppwp/n4861/temp.deduct.call#4
https://timsong-cpp.github.io/cppwp/n4861/temp.arg.explicit#7
^ permalink raw reply [flat|nested] 2+ messages in thread
* [Bug c++/103333] [accepts-invalid] function template argument deduction for incompatible 'transformed A' / 'deduced A' pair
2021-11-19 16:12 [Bug c++/103333] New: [accepts-invalid] function template argument deduction for incompatible 'transformed A' / 'deduced A' pair davveston at gmail dot com
@ 2021-11-22 18:15 ` leni536 at gmail dot com
0 siblings, 0 replies; 2+ messages in thread
From: leni536 at gmail dot com @ 2021-11-22 18:15 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103333
--- Comment #1 from Lénárd Szolnoki <leni536 at gmail dot com> ---
This can be turned into wrong-code.
C++11 example without includes:
```
template <bool, typename = void>
struct enable_if {};
template <typename T>
struct enable_if<true, T> {
using type = T;
};
template <bool b, typename T = void>
using enable_if_t = typename enable_if<b, T>::type;
template <typename T>
struct type_identity {
using type = T;
};
template <typename T>
using type_identity_t = typename type_identity<T>::type;
template <typename T>
struct is_const {
static constexpr bool value = false;
};
template <typename T>
struct is_const<const T> {
static constexpr bool value = true;
};
template<typename T, bool b>
struct S{
template<bool sfinae = true,
typename = enable_if_t<sfinae && !is_const<T>::value>>
operator S<T const, b>() { return {}; }
operator int() { return 0; }
};
inline int f(int, int) {
return 1;
}
template<typename T, bool b1, bool b2>
int f(S<const type_identity_t<T>, b1>,
S<T, b2>) {
return 2;
}
int main() {
S<int, true> s1{};
S<int, false> s2{};
return f(s1, s2); // returns 2, should return 1
}
```
https://godbolt.org/z/h8b75P7GK
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-11-22 18:15 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-19 16:12 [Bug c++/103333] New: [accepts-invalid] function template argument deduction for incompatible 'transformed A' / 'deduced A' pair davveston at gmail dot com
2021-11-22 18:15 ` [Bug c++/103333] " leni536 at gmail dot com
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).