[Bug c++/103110] templated operator auto is ignored

2021-11-06 Thread fchelnokov at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103110

--- Comment #6 from Fedor Chelnokov  ---
Thanks for the explanation! I reported Clang bug:
https://bugs.llvm.org/show_bug.cgi?id=52434

[Bug c++/103110] templated operator auto is ignored

2021-11-06 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103110

--- Comment #5 from Andrew Pinski  ---
(In reply to Fedor Chelnokov from comment #4)
> Actually you changed the example, and if T is void, then T{} is ill-formed.
> But I do not see how it relates to the original program.

I know I changed the example to show that clang is considering all templated
operator auto rather than not considering any of them.  This is why I am saying
clang is just plain out wrong of the way it handles templated operator auto.


class.conv.fct/6 is very explicit about this too:
A conversion function template shall not have a deduced return type (10.1.7.4).
[ Example:
struct S {
operator auto() const { return 10; } // OK
template
operator auto() const { return 1.2; } // error: conversion function template
};

- CUT 
So again clang is wrong.

[Bug c++/103110] templated operator auto is ignored

2021-11-06 Thread fchelnokov at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103110

--- Comment #4 from Fedor Chelnokov  ---
Actually you changed the example, and if T is void, then T{} is ill-formed. But
I do not see how it relates to the original program.

[Bug c++/103110] templated operator auto is ignored

2021-11-06 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103110

Andrew Pinski  changed:

   What|Removed |Added

 Status|UNCONFIRMED |RESOLVED
 Resolution|--- |INVALID

--- Comment #3 from Andrew Pinski  ---
clang gets it fully wrong anyways, take:
struct S {
template
operator auto() const  { return T{}; }
};

int main() {
S s;
[[maybe_unused]] int d = (int)s;
}
- CUT 
clang produces:
:3:38: error: illegal initializer type 'void'
operator auto() const  { return T{}; }
 ^
:8:35: note: in instantiation of function template specialization
'S::operator auto' requested here
[[maybe_unused]] int d = (int)s;
  ^
:8:30: error: no matching conversion for C-style cast from 'S' to 'int'
[[maybe_unused]] int d = (int)s;
 ^~
:3:5: note: candidate template ignored: substitution failure [with T =
void]
operator auto() const  { return T{}; }
^

- CUT 
There should be no instantiation of the template here at all.

[Bug c++/103110] templated operator auto is ignored

2021-11-06 Thread fchelnokov at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103110

--- Comment #2 from Fedor Chelnokov  ---
I think the program must be equivalent to
```
struct S {
operator auto() const { return 2; }
};

int main() {
S s;
[[maybe_unused]] int d = s;
}
```
and `auto` here is deduced from `return 2` and not from `template`

[Bug c++/103110] templated operator auto is ignored

2021-11-06 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103110

--- Comment #1 from Andrew Pinski  ---
I think this is a bug in clang as GCC, ICC (EDG) and MSVC all reject the code
for the same reason.
GCC even warns about it:
:3:14: warning: use of 'auto' in member template conversion operator
can never be deduced
3 | operator auto() const { return 2; }
  |  ^~~~