public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/99720] New: Feature Request: Better errors for C++ features when compiling C (pass by reference)
@ 2021-03-23  2:04 cameron at tacklind dot com
  2021-03-23  7:31 ` [Bug c/99720] " rguenth at gcc dot gnu.org
  2021-08-12 22:20 ` pinskia at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: cameron at tacklind dot com @ 2021-03-23  2:04 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99720

            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 thought
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 just
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 work to
convert to C++.

In implementing a simple function, without thinking, I used a reference (`void
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 that
simply does not exist in C.

Error message:
> test.c:1:13: error: expected ‘;’, ‘,’ or ‘)’ before ‘&’ token

It took me most of a day to realize I was trying to use a feature that simply
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 improve.

With how often C and C++ get conflated, it seems prudent to me to ensure that
accidentally using C++ features in a C compiler would generate warnings or
errors that point towards these possible mistake explicitly.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c/99720] Feature Request: Better errors for C++ features when compiling C (pass by reference)
  2021-03-23  2:04 [Bug c/99720] New: Feature Request: Better errors for C++ features when compiling C (pass by reference) cameron at tacklind dot com
@ 2021-03-23  7:31 ` rguenth at gcc dot gnu.org
  2021-08-12 22:20 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-03-23  7:31 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99720

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
           Keywords|                            |diagnostic
   Last reconfirmed|                            |2021-03-23
     Ever confirmed|0                           |1

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
Confirmed.  The caret diagnostic will probably ring a bell for the user but a
fixit hint would be nice indeed:

t.c:1:15: error: expected ';', ',' or ')' before '&' token
    1 | void foo (int &i);
      |               ^

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c/99720] Feature Request: Better errors for C++ features when compiling C (pass by reference)
  2021-03-23  2:04 [Bug c/99720] New: Feature Request: Better errors for C++ features when compiling C (pass by reference) cameron at tacklind dot com
  2021-03-23  7:31 ` [Bug c/99720] " rguenth at gcc dot gnu.org
@ 2021-08-12 22:20 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-12 22:20 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99720

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|2021-03-23 00:00:00         |2021-8-12
           Severity|normal                      |enhancement

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-08-12 22:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-23  2:04 [Bug c/99720] New: Feature Request: Better errors for C++ features when compiling C (pass by reference) cameron at tacklind dot com
2021-03-23  7:31 ` [Bug c/99720] " rguenth at gcc dot gnu.org
2021-08-12 22:20 ` 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).