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

Kang-Che Sung <Explorer09 at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|INVALID                     |---
             Status|RESOLVED                    |UNCONFIRMED

--- Comment #2 from Kang-Che Sung <Explorer09 at gmail dot com> ---
I think I missed details here:

1. I was trying to use the cplus_demangle() function provided from libiberty
(yes it was meant to be internal to GCC, GDB and binutils, but there have
already been outside uses and it's too late to stop that). To use
cplus_demangle(), it's necessary to `#include <demangle.h>`, which in turn
includes "libiberty.h" in the same directory.

2. The libiberty headers are provided in Debian and Ubuntu via the package
"libiberty-dev" (I'm sure other distros can provide a similar package, too.)
The headers demangle.h and libiberty.h would be installed in
/usr/include/libiberty , which means users programs can access it.

3. The warning can trigger with a test program like this:

```
/* -I/usr/include/libiberty -Wundef */
#include <demangle.h>

int main() { return 0; }
```

Here I didn't do anything but #include the header. I didn't attempt to call
basename() at all. With the compile options `-I/usr/include/libiberty
-Werror=undef` it would show the error like I quoted in the first comment.

### Steps to reproduce (in Debian or Ubuntu)

```
sudo apt install libiberty-dev
cat >test.c <<EOF
#include <demangle.h>
int main() { return 0; }
EOF
gcc -I/usr/include/libiberty -Werror=undef -o test test.c
```

The expected result is no errors or warnings.

A possible workaround is to replace `-I` option with `-isystem` so a "system"
header like this won't bring warnings to "user" programs.

Note that I'm okay when the header throws me an error when I actually call
basename() without doing AC_CHECK_DECLS with it. But if I'm not using
basename() at all, there shouldn't be warning.

Reply via email to