public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/107507] New: Conversion function templates are not sometimes not considered if the return type is type dependent
@ 2022-11-02 12:13 dangelog at gmail dot com
0 siblings, 0 replies; only message in thread
From: dangelog at gmail dot com @ 2022-11-02 12:13 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107507
Bug ID: 107507
Summary: Conversion function templates are not sometimes not
considered if the return type is type dependent
Product: gcc
Version: 12.2.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: dangelog at gmail dot com
Target Milestone: ---
Testcase:
template <typename T>
struct Test {
template <typename = void>
operator T();
};
int main() {
Test<int *> t;
int *x = t; // OK
int *y = t + 42; // ERROR
}
<source>: In function 'int main()':
<source>:20:16: error: no match for 'operator+' (operand types are 'Test<int*>'
and 'int')
228 | int *y = t + 42;
| ~ ^ ~~
| | |
| | int
| Test<int*>
This seems to depend on whether the conversion operators themselves are
function templates that return a type dependend on T. For instance, this works:
template <typename T>
struct Test {
template <typename = void>
operator int *(); // don't return a type that depends on T
};
int main() {
Test<int *> t;
int *x = t;
int *y = t + 42; // OK
}
And also this works:
template <typename T>
struct Test {
operator T(); // not a template
};
int main() {
Test<int *> t;
int *x = t;
int *y = t + 42;
}
I see that conversion function templates are treated in a special way in a
couple of places in the Standard but I'm not sure -- e.g. does
https://eel.is/c++draft/over.ics.user#3 apply here?. For comparison, Clang also
rejects this, while MSVC (in C++latest mode) accepts it.
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-11-02 12:13 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-02 12:13 [Bug c++/107507] New: Conversion function templates are not sometimes not considered if the return type is type dependent dangelog 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).