This is the mail archive of the newlib@sourceware.org mailing list for the newlib 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]

Re: C++ and feature guards Warning Question


On 06/04/2017 07:18, Joel Sherrill wrote:

Trying to compile an open source package for RTEMS, I
came across something I need help to figure out how
best to address. The package is in C++ and giving a
lot of warnings on methods which I would have thought
are prototyped. But clearly the compiler settings
are tripping the guards different than the package
authors expect.

Native GCC on CentOS 7 with glibc gives no warnings.
It could easily be a GCC version side-effect.

==========================
#include <stdlib.h>

int f(char *s)
{
  return mkstemp(s);
}
==========================

Warnings with i386-rtems GCC and newilb:

$ i386-rtems4.12-gcc -c j.cc
$ i386-rtems4.12-gcc -std=c++11 -c j.cc
j.cc: In function 'int f(char*)':
j.cc:5:19: error: 'mkstemp' was not declared in this scope
   return mkstemp(s);
$ i386-rtems4.12-gcc -std=c++03 -c j.cc
j.cc: In function 'int f(char*)':
j.cc:5:19: error: 'mkstemp' was not declared in this scope
   return mkstemp(s);
$ i386-rtems4.12-gcc --version
i386-rtems4.12-gcc (GCC) 6.3.0 20161221 (RTEMS 4.12, RSB
4c5eb8969451c4ea0997b3caa98bfe80fe15da69, Newlib 2.5.0.20170228)

Native GCC and glibc results:

$ gcc -std=c++03 -c j.cc
$ gcc -std=c++11 -c j.cc
$ gcc -std=c++11 ^C j.cc
$ gcc --version
gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-11)

Suggestions on what to do to eliminate the warnings is
appreciated.


I built the code on FreeBSD with clang and the result is the same as Linux:

$ cc -std=c++03 -c j.cc
$ cc -std=c++11 -c j.cc
$ cc --version
FreeBSD clang version 3.8.0 (tags/RELEASE_380/final 262564) (based on LLVM 3.8.0)
Target: x86_64-unknown-freebsd11.0
Thread model: posix
InstalledDir: /usr/bin

Adding -save-temps to the builds I see `mkstemp` is guarded with:

#if __MISC_VISIBLE || __POSIX_VISIBLE >= 200112 || __XSI_VISIBLE >= 4

and FreeBSD has:

#if __POSIX_VISIBLE >= 200809 || __XSI_VISIBLE

I hope this helps.

Chris


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