From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id D4F7A3857354; Thu, 29 Sep 2022 18:31:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D4F7A3857354 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1664476274; bh=0FDeGdTh6eRaqp5Qc2c6QXtv/3+daPrle3PttnHaHQE=; h=From:To:Subject:Date:From; b=lm8xoPtWo7TOrFzRBwD+037jmamtRH9hczwDCcKqdQTyZFynTwEA01GYNA3cVaSr3 8KDhPBXGi/be3/z/4u9x1iqejAiwAkyiDMw6uVdGyZsQ74yzk1BeZG4p0iCmn+bgme v6r12IkIR0Dtj5jvLH2AjAcYkRZesbt4lC7R0tYI= From: "Keith.S.Thompson at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/107091] New: Misleading error message "incompatible types when returning ..." Date: Thu, 29 Sep 2022 18:30:52 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Version: 12.2.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: Keith.S.Thompson at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D107091 Bug ID: 107091 Summary: Misleading error message "incompatible types when returning ..." Product: gcc Version: 12.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: Keith.S.Thompson at gmail dot com Target Milestone: --- When I compile this source file: double bad(void) { return (void*)0; } double good(void) { return 42; } I get this output from gcc 12.2.0 (and from earlier versions): c.c: In function =E2=80=98bad=E2=80=99: c.c:2:12: error: incompatible types when returning type =E2=80=98void *=E2= =80=99 but =E2=80=98double=E2=80=99 was expected 2 | return (void*)0; | ^ It's true that it's a constraint violation, and it's true that void* and do= uble are incompatible, but type compatibility is not required here. The problem = is that there is no implicit conversion from void* to double. In the "good" function, int and double are also incompatible types, but the= re is an implicit conversion so the statement is valid. Note that g++ produces this correct message for the equivalent C++ code: c.cpp: In function =E2=80=98double bad()=E2=80=99: c.cpp:2:19: error: cannot convert =E2=80=98void*=E2=80=99 to =E2=80=98doubl= e=E2=80=99 in return 2 | return (void*)0; |=20=20=20=20=20=20=20=20=20=20 This was brought to my attention by this post on Stack Overflow: https://stackoverflow.com/q/73899947/827263 Reference for compatible types: C11 (or N1570) 6.2.7.=