From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 472293858004; Tue, 23 Mar 2021 02:04:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 472293858004 From: "cameron at tacklind dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/99720] New: Feature Request: Better errors for C++ features when compiling C (pass by reference) Date: Tue, 23 Mar 2021 02:04:11 +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: 9.3.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: cameron at tacklind 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 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 23 Mar 2021 02:04:11 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D99720 Bug ID: 99720 Summary: Feature Request: Better errors for C++ features when compiling C (pass by reference) Product: gcc Version: 9.3.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: cameron at tacklind dot com Target Milestone: --- I'm embarrassed that I spent so long on this issue, to the point that I tho= ught it was worth writing this issue in the hope that it might save someone the = same trouble. If this is inappropriate (or already address), my apologies. I normally work in the C++ world for simple embedded programming, mostly ju= st with a subset of the language features. I love the sugar. The old "C" way of doing things has always bugged me. I'm thinking of basic features like overloading function. Now I'm working on a project that has a lot of legacy C that's too much wor= k to convert to C++. In implementing a simple function, without thinking, I used a reference (`v= oid foo(int&i);`) to pass a variable to a function (not a plain pointer). The astute among you will remember that passing by reference is a C++ feature t= hat simply does not exist in C. Error message: > test.c:1:13: error: expected =E2=80=98;=E2=80=99, =E2=80=98,=E2=80=99 or = =E2=80=98)=E2=80=99 before =E2=80=98&=E2=80=99 token It took me most of a day to realize I was trying to use a feature that simp= ly doesn't exist in C (lots of other #define macros that contributed to my confusion). It feels like this error message should be easy enough to impro= ve. With how often C and C++ get conflated, it seems prudent to me to ensure th= at accidentally using C++ features in a C compiler would generate warnings or errors that point towards these possible mistake explicitly.=