Copying from internal bug b/30353757
Got fixed in bionic upstream in https://android-review.googlesource.com/#/c/250323/
TL;DR
arch-arm/usr/include/sys/cdefs.h re-defines __func__ = __PRETTY_FUNCTION__
This causes the following problems:
- Breaks C++99 section 6.4.2.2
- Is inconsistent with glibc headers, which don't define (at least on debian wheezy) __func__ at all, and maintain the original gcc behavior where __func__ == __FUNCTION__ (!=__PRETTY_FUNCTION__)
- Is inconsistent with GCC doc (https://gcc.gnu.org/onlinedocs/gcc/Function-Names.html) that says
"_FUNCTION__ is another name for __func__, provided for backward compatibility with old versions of GCC."
(For the lovers of the genre who still believe and rely on GCC docs consistency)
Repro steps:
$ cat > /tmp/repro.cc <<EOF
void getFunctPre(const char** a, const char** b) {
*a = __func__;
*b = __FUNCTION__;
}
#include <stdio.h>
void getFunctPost(const char** a, const char** b) {
*a = __func__;
*b = __FUNCTION__;
}
int main() {
const char* a, *b;
printf("\nPRE stdio include\n");
getFunctPre(&a, &b);
printf("__func__ = %s\n__FUNCTION__ = %s\n", a, b);
printf("\nPOST stdio include\n");
getFunctPost(&a, &b);
printf("__func__ = %s\n__FUNCTION__ = %s\n", a, b);
return 0;
}
EOF
$ ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-g++ \
-pie --sysroot=ndk/platforms/android-16/arch-arm -march=armv7-a -mthumb \
-o /tmp/test /tmp/test.cc -std=c++11
$ adb push /tmp/test /data/local/tmp/test && adb shell /data/local/tmp/test
PRE stdio include
__func__ = getFunctPre
__FUNCTION__ = getFunctPre
POST stdio include
__func__ = void getFunctPost(const char**, const char**) !!!!!!!!!!!!!!!!!!!!!!!!!!!!
__FUNCTION__ = getFunctPost
The culprit seems in ndk/platforms/android-16/arch-arm/usr/include/sys/cdefs.h
/*
* C99 defines __func__ predefined identifier, which was made available
* in GCC 2.95.
*/
#if !defined(__STDC_VERSION__) || !(__STDC_VERSION__ >= 199901L)
#if __GNUC_PREREQ(2, 6)
#define __func__ __PRETTY_FUNCTION__
#elif __GNUC_PREREQ(2, 4)
#define __func__ __FUNCTION__
#else
#define __func__ ""
#endif
#endif /* !(__STDC_VERSION__ >= 199901L) */
I think this sections should just be ripped out. __func__ should be a builtin in modern compilers.
Comment 1 by bugdroid1@chromium.org
, Jul 26 2016