This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[C++ PATCH] Warn about use of __func__ when -pedantic


While reviewing C++0x features that GCC already provides support for,
I noticed that we don't bother to complain about the C99 "__func__"
feature in strict C++98 mode, even though this feature is not part of
C++ 1998/2003. __func__ is a part of C++0x (with the same definition
as in C99).

We can do one of two things:

  1) Warn about the use of __func__ in C++98 mode when -pedantic (the
attached patch).
  2) Never warn about __func__ (status quo, all though I'd like to
commit the testcase in this patch).

I don't have a strong preference regarding which way we go. Rejecting
ill-formed code when given "-pedantic" is generally a good thing, but
__func__ is so benign that I'm not sure I care. The warning may cause
more harm than good, so I'm slightly leaning toward #2. Opinions?

Either way, I'd like to commit the new testcase
(g++.dg/cpp0x/__func__.C), which checks that __func__ doesn't cause a
diagnostic in C++0x mode. It's fine both with and without the attached
patch. Regardless, I'll also update gcc-4.3/cxx0x_status.html to
reflect support for "__func__" in C++0x mode.

Patch tested i386-apple-darwin8.11.1, no regressions.

  - Doug

2007-12-13  Douglas Gregor  <doug.gregor@gmail.com>

	* parser.c (cp_parser_primary_expression): Warn about __func__
	when -pedantic in C++98 mode.

2007-12-13  Douglas Gregor  <doug.gregor@gmail.com>

	* g++.old-deja/g++.ext/pretty4.C: Use __extension__ to suppress
	warning about __func__.
	* g++.dg/ext/fnname1.C: Ditto.
	* g++.dg/ext/fnname2.C: Ditto.
	* g++.dg/ext/fnname3.C: Ditto.
	* g++.dg/cpp0x/__func__.C: New.

Attachment: __func__.patch
Description: Binary data


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]