tech-toolchain archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Proposal to stop redefining __func__ for C++11 and newer



We define a fallback version of __func__ for pre-C99 compilers in
<sys/cdefs.h>

416 /*
417  * C99 defines __func__ predefined identifier, which was made available
418  * in GCC 2.95.
419  */
420 #if !(__STDC_VERSION__ >= 199901L)
421 #if __GNUC_PREREQ__(2, 6)
422 #define	__func__	__PRETTY_FUNCTION__
423 #elif __GNUC_PREREQ__(2, 4)
424 #define	__func__	__FUNCTION__
425 #else
426 #define	__func__	""
427 #endif
428 #endif /* !(__STDC_VERSION__ >= 199901L) */

-- https://nxr.netbsd.org/xref/src/sys/sys/cdefs.h#416

__func__ has been imported into C++11 along with the C99 compatibility
support and I believe that by accident we redefine it for all C++ programs.

According to C++ papers, __func__ is an implementation-defined string.

-- http://eel.is/c++draft/dcl.dcl#dcl.fct.def.general-8

However the current version causes a mismatch between NetBSD and the world:

$ cat test.cc
#include <stdio.h>
int
main(int argc, char **argv)
{
	printf("%s\n", __func__);
	return 0;
}
$ ./a.out
int main(int, char **)

vs others:

$ cat test.cc
#include <stdio.h>
int
main(int argc, char **argv)
{
	printf("%s\n", __func__);
	return 0;
}
$ ./a.out
main

The same behavior is presented in G++ and Clang++.

While both versions are compliant with C++11, this causes unnecessary
difference in regression tests, in particular in the LLVM project.

I wrote a patch to stop redefining __func__ for C++11, analogous to the
existing logic for C99.

http://netbsd.org/~kamil/patch-00076-__func__-cpp11.txt

I've found that a similar issue was also detected at least in fish shell
and developers mentioned the NetBSD case in the thread.

https://github.com/fish-shell/fish-shell/commit/574851f092358f5834afb0b529676924fcbd59c6

I've discussed this with Michal, who has detected the issue in the LLVM
regression tests (https://reviews.llvm.org/D55162) and he has a
different opinion on __func__ and C++. I will let him explain it here.

Attachment: signature.asc
Description: OpenPGP digital signature



Home | Main Index | Thread Index | Old Index