public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/107495] New: GCC does not consider the right contextual implicit conversions
@ 2022-11-01 14:23 dangelog at gmail dot com
2022-11-01 14:43 ` [Bug c++/107495] " dangelog at gmail dot com
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: dangelog at gmail dot com @ 2022-11-01 14:23 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107495
Bug ID: 107495
Summary: GCC does not consider the right contextual implicit
conversions
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:
struct Test {
operator int *() const;
operator void *() const;
};
int main() {
Test t;
delete t;
}
GCC rejects this:
<source>: In function 'int main()':
<source>:32:12: error: ambiguous default type conversion from 'Test'
32 | delete t;
| ^
<source>:32:12: note: candidate conversions include 'Test::operator void*()
const' and 'Test::operator int*() const'
<source>:32:12: error: type 'struct Test' argument given to 'delete', expected
pointer
But this is wrong. https://eel.is/c++draft/expr.delete#1.sentence-5 says "If of
class type, the operand is contextually implicitly converted to a pointer to
object type" and the attached note explicitly says "This implies that an object
cannot be deleted using a pointer of type void* because void is not an object
type".
The definition of contextual conversion says
https://eel.is/c++draft/conv#general-5 :
"C is searched for non-explicit conversion functions whose return type is cv T
or reference to cv T such that T is allowed by the context. There shall be
exactly one such T."
There is exactly one such T (conversion to pointer of object type), so GCC is
rejecting valid code.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/107495] GCC does not consider the right contextual implicit conversions
2022-11-01 14:23 [Bug c++/107495] New: GCC does not consider the right contextual implicit conversions dangelog at gmail dot com
@ 2022-11-01 14:43 ` dangelog at gmail dot com
2022-11-01 17:54 ` mpolacek at gcc dot gnu.org
2022-12-09 19:42 ` pinskia at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: dangelog at gmail dot com @ 2022-11-01 14:43 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107495
--- Comment #1 from Giuseppe D'Angelo <dangelog at gmail dot com> ---
Variation of the above:
struct Test {
template <class = void>
operator int *() const;
};
Test t;
delete t;
also fails:
<source>: In function 'int main()':
<source>:32:12: error: default type conversion cannot deduce template argument
for 'template<class> Test::operator int*() const'
32 | delete t;
| ^
<source>:32:12: error: type 'struct Test' argument given to 'delete', expected
pointer
But here I'm not 100% sure; is there is supposed to be any template argument
deduction? Clang rejects this as well, while MSVC accepts it.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/107495] GCC does not consider the right contextual implicit conversions
2022-11-01 14:23 [Bug c++/107495] New: GCC does not consider the right contextual implicit conversions dangelog at gmail dot com
2022-11-01 14:43 ` [Bug c++/107495] " dangelog at gmail dot com
@ 2022-11-01 17:54 ` mpolacek at gcc dot gnu.org
2022-12-09 19:42 ` pinskia at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2022-11-01 17:54 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107495
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |mpolacek at gcc dot gnu.org
--- Comment #2 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
I think here the problem is that delete_sanity uses
627 t = build_expr_type_conversion (WANT_POINTER, exp, true);
but WANT_POINTER includes 'void*'. I suppose we'll need
WANT_POINTER_TO_OBJECT, a subset of WANT_POINTER, and use it in delete_sanity.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/107495] GCC does not consider the right contextual implicit conversions
2022-11-01 14:23 [Bug c++/107495] New: GCC does not consider the right contextual implicit conversions dangelog at gmail dot com
2022-11-01 14:43 ` [Bug c++/107495] " dangelog at gmail dot com
2022-11-01 17:54 ` mpolacek at gcc dot gnu.org
@ 2022-12-09 19:42 ` pinskia at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-12-09 19:42 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107495
--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Giuseppe D'Angelo from comment #1)
> Variation of the above:
The testcase in comment #1 is almost definitely the same as PR 59328.
Note the testcase in comment #0 is also rejected by clang ...
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-12-09 19:42 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-01 14:23 [Bug c++/107495] New: GCC does not consider the right contextual implicit conversions dangelog at gmail dot com
2022-11-01 14:43 ` [Bug c++/107495] " dangelog at gmail dot com
2022-11-01 17:54 ` mpolacek at gcc dot gnu.org
2022-12-09 19:42 ` pinskia at gcc dot gnu.org
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).