Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #81326 > unrolled thread
| Started by | Bonita Montero <Bonita.Montero@gmail.com> |
|---|---|
| First post | 2021-09-19 13:33 +0200 |
| Last post | 2021-09-19 18:03 +0200 |
| Articles | 2 — 1 participant |
Back to article view | Back to comp.lang.c++
Explicit instantiation of a class with concept'ed methods Bonita Montero <Bonita.Montero@gmail.com> - 2021-09-19 13:33 +0200
Re: Explicit instantiation of a class with concept'ed methods Bonita Montero <Bonita.Montero@gmail.com> - 2021-09-19 18:03 +0200
| From | Bonita Montero <Bonita.Montero@gmail.com> |
|---|---|
| Date | 2021-09-19 13:33 +0200 |
| Subject | Explicit instantiation of a class with concept'ed methods |
| Message-ID | <si775f$ogi$1@dont-email.me> |
Look at this code:
#include <concepts>
using namespace std;
struct A
{
void op();
};
struct B
{
void op( bool );
};
template<typename T>
concept concept_C = is_same<T, A>::value || is_same<T, B>::value;
template<typename T>
requires concept_C<T>
struct C
{
void opA()
requires is_same<T, A>::value;
void opB( bool f )
requires is_same<T, B>::value;
T *pt;
};
template<typename T>
requires concept_C<T>
void C<T>::opA()
requires is_same<T, A>::value
{
pt->op();
}
template<typename T>
requires concept_C<T>
void C<T>::opB( bool f )
requires is_same<T, B>::value
{
pt->op( f );
}
template
struct C<A>;
template
struct C<B>;
MSVC will instantiate opA for A as well as B and opB
also for A as well as B and gives the following errors:
(42,10): error : too many arguments to function call, expected 0, have 1
(46,8): message : in instantiation of member function 'C<A>::opB'
requested here
(7,7): message : 'op' declared here
(34,9): error : too few arguments to function call, expected 1, have 0
(49,8): message : in instantiation of member function 'C<B>::opA'
requested here
(12,7): message : 'op' declared here
clang gives similar errors, but g++12 is smarter and skips inappropriate
compilation, i.e. filters the functions through their concepts, i.e. it
compiles opA only for A and opB only for B - so which compiler is right
here ? And is there a workaround ?
[toc] | [next] | [standalone]
| From | Bonita Montero <Bonita.Montero@gmail.com> |
|---|---|
| Date | 2021-09-19 18:03 +0200 |
| Message-ID | <si7mvn$fli$1@dont-email.me> |
| In reply to | #81326 |
I wrote the same thing on Stack Overflow. C<A>::opB( bool ) and C<B>::opA() shouldn't be instantiated according to the standard. So this is a bug of clang. MSVC has fixed the bug in the latest release.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.c++
csiph-web