bug-gnulib
[Top][All Lists]
Advanced

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

Re: cannot figure out how to work with GNULIB_NAMESPACE without warnings


From: Alexandre Duret-Lutz
Subject: Re: cannot figure out how to work with GNULIB_NAMESPACE without warnings
Date: Thu, 14 Jan 2021 11:35:24 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

Hi Bruno!

Bruno Haible <bruno@clisp.org> writes:

> in C++, it is easier and more robust to define GNULIB_NAMESPACE.

OK, thanks, I'll progress this way.

>> /usr/sbin/../lib64/gcc/x86_64-pc-linux-gnu/10.2.0/../../../../include/c++/10.2.0/bits/basic_string.h:6652:50:
>>  error: The symbol ::vsnprintf refers to the system function. Use 
>> gnulib::vsnprintf instead. [-Werror,-Wuser-defined-warnings]
>
> You decide whether to follow this suggestion. If you follow it, this warning
> will disappear. If you don't follow it, at the end of going through all
> warnings, you add '-Wno-user-defined-warnings' to your CPPFLAGS, and are done
> with it.

I have a few questions about this:

- Would it be possible to provide a way to disable only the warnings
  emitted by _GL_CXXALIASWARN? (or maybe one of the macro it calls, I
  don't know where is the right place) Removing all user-defined
  warnings with -Wno-user-defined-warnings will hide other important
  messages.

  For instance libc++ uses diagnose_if attributes to warn about
  some common C++ errors.  They even provide a
  _LIBCPP_DISABLE_ADDITIONAL_DIAGNOSTICS macro to disable those.
  (this macro appears on https://libcxx.llvm.org/docs/UsingLibcxx.html)

- Is there a way to detect that the function is being called
  in a system header and use that in the diagnose_if condition?
  If possible, that would allow removing some false positives.
  In the case I reported, the warning about vsnprintf is
  in a system-header on a system where @REPLACE_VSNPRINTF@=0,
  so the warning is clearly noisy.

- Do I understand correctly that those warnings are supposed to be
  emitted everywhere I forgot to use the gnulib:: namespace before the
  call of a replaceable function?  Even on systems where no replacement
  function is used?  I did not see any such warning when I first
  compiled with g++ and GNULIB_NAMESPACE, and after reading the
  "drawback" paragraph near the end of page
  
https://www.gnu.org/software/gnulib/manual/html_node/A-C_002b_002b-namespace-for-gnulib.html
  I assumed I was on my own to find all the places where gnulib::
  should be added.  It's only when some continuous integration
  builds failed that I discovered that clang++ would emit warnings [*].
  Having now looked at _GL_CXXALIASWARN it seems the warnings are
  disabled when GCC optimizes, which is the default with Autoconf.
  May this page could mention that some built-in help is available, and
  how to get it.  Something like:

     To help with finding function names that should be prefixed by
     gnulib::, Gnulib equips the original functions in the global
     namespace with an attribute that will trigger warnings when those
     functions are called.  This only works with g++ when not optimizing
     (-O0), or with clang++, so you may want to give one of these two
     compilers a go after you activate GNULIB_NAMESPACE.



[*] I would have not noticed those warnings if those builds were not
setup with -Werror.  That's one reason why I try to get warning-less
builds: so that I do not miss useful messages that appear only in some
build configurations.  Another reason is that I build a library; I want
the headers I install to follow the strictest standard I can, so that
users of those headers are not annoyed by warnings I could have avoided.
(Obviously I'm not installing the gnulib headers, so I have a bit more
freedom here.)

--
Alexandre Duret-Lutz



reply via email to

[Prev in Thread] Current Thread [Next in Thread]