[Bug c++/30811] __FUNCTION__ allowed in function declaration (i.e. add -Wpredefined-identifier-outside-function)

2022-01-24 Thread egallager at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=30811

Eric Gallager  changed:

   What|Removed |Added

Summary|__FUNCTION__ allowed in |__FUNCTION__ allowed in
   |function declaration|function declaration (i.e.
   ||add
   ||-Wpredefined-identifier-out
   ||side-function)
 Blocks||87403

--- Comment #10 from Eric Gallager  ---
(In reply to Andrew Pinski from comment #9)
> Note clang warns but its warning is not so clear:
> :4:27: warning: predefined identifier is only valid inside function
> [-Wpredefined-identifier-outside-function]
> void bar (const char *s = __FUNCTION__) { puts (s); }
>   ^
> :5:27: warning: predefined identifier is only valid inside function
> [-Wpredefined-identifier-outside-function]
> void baz (const char *s = __PRETTY_FUNCTION__) { puts (s); }
>   ^
> 
> At least MSVC is clear on what is going on:
> (4): error C2457: '__FUNCTION__': predefined macro cannot appear
> outside of a function body

adding clang's name for the warning to the title, so that this can block the
"new warning" meta-bug


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87403
[Bug 87403] [Meta-bug] Issues that suggest a new warning

[Bug c++/30811] __FUNCTION__ allowed in function declaration

2022-01-24 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=30811

Andrew Pinski  changed:

   What|Removed |Added

   Keywords||accepts-invalid, diagnostic

--- Comment #9 from Andrew Pinski  ---
Note clang warns but its warning is not so clear:
:4:27: warning: predefined identifier is only valid inside function
[-Wpredefined-identifier-outside-function]
void bar (const char *s = __FUNCTION__) { puts (s); }
  ^
:5:27: warning: predefined identifier is only valid inside function
[-Wpredefined-identifier-outside-function]
void baz (const char *s = __PRETTY_FUNCTION__) { puts (s); }
  ^

At least MSVC is clear on what is going on:
(4): error C2457: '__FUNCTION__': predefined macro cannot appear
outside of a function body

[Bug c++/30811] __FUNCTION__ allowed in function declaration

2017-08-28 Thread egallager at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=30811

Eric Gallager  changed:

   What|Removed |Added

 Status|UNCONFIRMED |NEW
   Last reconfirmed|2016-02-02 00:00:00 |2017-08-28
 CC||egallager at gcc dot gnu.org
 Ever confirmed|0   |1

--- Comment #8 from Eric Gallager  ---
(In reply to Martin Sebor from comment #7)
> I believe besides an enhancement request there's a bug here: The 
> __builtin_FUNCTION() intrinsic is documented as "the equivalent to the
> preprocessor __FUNCTION__ macro and returns the function name the invocation
> of 
> the built-in is in."  However, as the following test case shows, the
> intrinsic evaluates to a pointer to a different string than __FUNCTION__,
> and so it's not equivalent.  Perhaps it's just a matter of correcting the
> documentation.
> 
> This is with the latest trunk of 6.0:
> 
> $ cat t.c && /build/gcc-trunk/gcc/xgcc -B /build/gcc-trunk/gcc -O2 -Wall
> -Wextra -xc++ t.c && ./a.out
> #define F(f, ff) \
> void f (const char *s = ff) { \
> __builtin_printf (#ff " = \"%s\"\n", s); \
> }
> 
> F (f0, __func__);
> F (f1, __FUNCTION__);
> F (f2, __PRETTY_FUNCTION__);
> F (f3, __builtin_FUNCTION());
> 
> int main () {
> f0 ();
> f1 ();
> f2 ();
> f3 ();
> }
> t.c:6:8: warning: ‘__func__’ is not defined outside of function scope
>  F (f0, __func__);
> ^
> 
> t.c:2:29: note: in definition of macro ‘F’
>  void f (const char *s = ff) { \
>  ^~
> 
> __func__ = ""
> __FUNCTION__ = ""
> __PRETTY_FUNCTION__ = "top level"
> __builtin_FUNCTION() = "main"

Confirmed, I get the same output.

[Bug c++/30811] __FUNCTION__ allowed in function declaration

2016-02-02 Thread msebor at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=30811

Martin Sebor  changed:

   What|Removed |Added

   Last reconfirmed||2016-2-2

--- Comment #7 from Martin Sebor  ---
I believe besides an enhancement request there's a bug here: The 
__builtin_FUNCTION() intrinsic is documented as "the equivalent to the
preprocessor __FUNCTION__ macro and returns the function name the invocation of 
the built-in is in."  However, as the following test case shows, the intrinsic
evaluates to a pointer to a different string than __FUNCTION__, and so it's not
equivalent.  Perhaps it's just a matter of correcting the documentation.

This is with the latest trunk of 6.0:

$ cat t.c && /build/gcc-trunk/gcc/xgcc -B /build/gcc-trunk/gcc -O2 -Wall
-Wextra -xc++ t.c && ./a.out
#define F(f, ff) \
void f (const char *s = ff) { \
__builtin_printf (#ff " = \"%s\"\n", s); \
}

F (f0, __func__);
F (f1, __FUNCTION__);
F (f2, __PRETTY_FUNCTION__);
F (f3, __builtin_FUNCTION());

int main () {
f0 ();
f1 ();
f2 ();
f3 ();
}
t.c:6:8: warning: ‘__func__’ is not defined outside of function scope
 F (f0, __func__);
^

t.c:2:29: note: in definition of macro ‘F’
 void f (const char *s = ff) { \
 ^~

__func__ = ""
__FUNCTION__ = ""
__PRETTY_FUNCTION__ = "top level"
__builtin_FUNCTION() = "main"

[Bug c++/30811] __FUNCTION__ allowed in function declaration

2007-03-09 Thread sebor at roguewave dot com


--- Comment #6 from sebor at roguewave dot com  2007-03-09 18:25 ---
(In reply to comment #5)

Good point! I hadn't thought of that. Since that option is out and __FUNCTION__
should simply behave identically to __func__ and be disallowed in global or
namespace scope function argument lists, or its documentation should be changed
to say that unlike __func__, __FUNCTION__ is allowed in argument lists of C++
functions declared at namespace scope.

The point is that if the two are documented to be interchangeable users ought
to be able to switch between one and the other with no change in behavior.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30811



[Bug c++/30811] __FUNCTION__ allowed in function declaration

2007-03-08 Thread bangerth at dealii dot org


--- Comment #5 from bangerth at dealii dot org  2007-03-09 03:43 ---
If you make it defined earlier than the standard says, then you
get into trouble for cases like this:

  void f() {
struct X {
  void g(const char * = __FUNCTION__) {}
};
  }

According to the N1970, this refers to the string "void f()", but
by your proposal it would be something like "...X::g()".

W.


-- 

bangerth at dealii dot org changed:

   What|Removed |Added

 CC||bangerth at dealii dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30811



[Bug c++/30811] __FUNCTION__ allowed in function declaration

2007-02-15 Thread sebor at roguewave dot com


--- Comment #4 from sebor at roguewave dot com  2007-02-15 23:06 ---
The wording proposed in N1970 for the C++ __func__ indentifier reads: 

  -1- The identifier __func__ shall be implicitly declared by the translator
  as if, immediately following the opening brace of each function definition,
  the declaration

  static const char __func__[] = "function-name";

  appeared, where function-name is the unqualified name of the lexically
  enclosing function.

See http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n1970.htm.

Based on this __func__ would not be defined in a function declaration (except
as an extension).

Since the gcc __FUNCTION__ extension does not behave the same way as the C99
__func__ indentifier (i.e., it is defined in a function declaration, albeit
to the empty string), it might be possible to extend it and make it defined
"earlier," i.e., even before the opening curly brace. Another option, of
course, is to undefine it and make it exactly the same as __func__. I see
more value in doing the former than the latter.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30811



[Bug c++/30811] __FUNCTION__ allowed in function declaration

2007-02-15 Thread pinskia at gcc dot gnu dot org


--- Comment #3 from pinskia at gcc dot gnu dot org  2007-02-15 22:54 ---
IIRC __FUNCTION__ is really __func__ defined by the C99 standard.  So is
__func__ allowed as a default argument in the C++0x?


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30811



[Bug c++/30811] __FUNCTION__ allowed in function declaration

2007-02-15 Thread sebor at roguewave dot com


--- Comment #2 from sebor at roguewave dot com  2007-02-15 21:29 ---
No, I'm not aware of any such paper. AFAIK, neither __FUNCTION__ nor
__PRETTY_FUNCTION__ is specified by either C or C++, or proposed for inclusion
either of them (I could be wrong). They're gcc extensions, aren't they?

I'm suggesting that __FUNCTION__ either behave the way it's documented (i.e.,
just as C99 __func__ does) or, since it is an extension, that it be extended
further. Similarly for __PRETTY_FUNCTION__.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30811



[Bug c++/30811] __FUNCTION__ allowed in function declaration

2007-02-15 Thread pinskia at gcc dot gnu dot org


--- Comment #1 from pinskia at gcc dot gnu dot org  2007-02-15 21:17 ---
Do you know the status of the C++0x paper about this C99 "extension"?


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30811