public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/102493] New: non-type template specialization for member pointer to field and function reports leads to unexpected conflict
@ 2021-09-26 17:23 marekr22 at wp dot pl
2023-07-25 13:54 ` [Bug c++/102493] " jehelset at gmail dot com
0 siblings, 1 reply; 2+ messages in thread
From: marekr22 at wp dot pl @ 2021-09-26 17:23 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102493
Bug ID: 102493
Summary: non-type template specialization for member pointer to
field and function reports leads to unexpected
conflict
Product: gcc
Version: 11.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: marekr22 at wp dot pl
Target Milestone: ---
Here is minimum complete verifiable example (C++17):
```cpp
#include <iostream>
#include <string>
#include <type_traits>
template <auto Fp>
struct field_type;
template<typename R, typename T, R (T::*FP)>
struct field_type<FP>
{
using type = R;
};
template<typename R, typename T, typename...Args, R (T::*FP)(Args...)>
struct field_type<FP>
{
using type = R;
};
template<auto FP>
using field_type_t = typename field_type<FP>::type;
class Foo {
public:
int x = 0;
double y = 0;
std::string s;
const int cx = 0;
Foo() = default;
void bar() {
std::cout << "bar\n";
}
int par(int z) {
std::cout << "bar\n";
return z;
}
};
template<auto F, typename T>
constexpr bool test = std::is_same_v<field_type_t<F>, T>;
static_assert(test<&Foo::x, int>, "");
static_assert(test<&Foo::cx, const int>, "");
static_assert(test<&Foo::s, std::string>, "");
static_assert(test<&Foo::y, double>, "");
#ifndef HIDE_PROBLEM_ON_GCC_11
static_assert(test<&Foo::bar, void>, "");
static_assert(test<&Foo::par, int>, "");
#endif
```
This compile on all compilers https://godbolt.org/z/31svobz3z
except for gcc 11.1 and 11.2 (gcc 10.3 works).
Reported error is:
```
<source>: In substitution of 'template<auto FP> using field_type_t = typename
field_type::type [with auto FP = &Foo::bar]':
<source>:44:28: required from 'constexpr const bool test<&Foo::bar, void>'
<source>:51:15: required from here
<source>:21:7: error: ambiguous template instantiation for 'struct
field_type<&Foo::bar>'
21 | using field_type_t = typename field_type<FP>::type;
| ^~~~~~~~~~~~
<source>:9:8: note: candidates are: 'template<class R, class T, R T::* FP>
struct field_type<FP> [with R = void(); T = Foo; R T::* FP = &Foo::bar]'
9 | struct field_type<FP>
| ^~~~~~~~~~~~~~
<source>:15:8: note: 'template<class R, class T, class ...
Args, R (T::* FP)(Args ...)> struct field_type<FP> [with R = void; T = Foo;
Args = {}; R (T::* FP)(Args ...) = &Foo::bar]'
15 | struct field_type<FP>
| ^~~~~~~~~~~~~~
<source>:21:7: error: invalid use of incomplete type 'struct
field_type<&Foo::bar>'
21 | using field_type_t = typename field_type<FP>::type;
| ^~~~~~~~~~~~
<source>:6:8: note: declaration of 'struct field_type<&Foo::bar>'
6 | struct field_type;
| ^~~~~~~~~~
```
^ permalink raw reply [flat|nested] 2+ messages in thread
* [Bug c++/102493] non-type template specialization for member pointer to field and function reports leads to unexpected conflict
2021-09-26 17:23 [Bug c++/102493] New: non-type template specialization for member pointer to field and function reports leads to unexpected conflict marekr22 at wp dot pl
@ 2023-07-25 13:54 ` jehelset at gmail dot com
0 siblings, 0 replies; 2+ messages in thread
From: jehelset at gmail dot com @ 2023-07-25 13:54 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102493
--- Comment #1 from John Eivind Helset <jehelset at gmail dot com> ---
ran into this today as well with:
```cpp
struct X{
void f(char){}
};
template<auto X>
struct Y{};
template<typename T,typename U,T U::* ptr>
struct Y<ptr>{};
template<typename T,typename U,typename... A,T (U::*ptr)(A...)>
struct Y<ptr>{};
Y<&X::f> y;
```
using gcc 13.1.1, clang trunk accepted same code.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-07-25 13:54 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-26 17:23 [Bug c++/102493] New: non-type template specialization for member pointer to field and function reports leads to unexpected conflict marekr22 at wp dot pl
2023-07-25 13:54 ` [Bug c++/102493] " jehelset 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).