public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/97044] New: Undefined format macros because of include order on AIX
@ 2020-09-14  9:07 clement.chigot at atos dot net
  2020-09-20 20:10 ` [Bug libstdc++/97044] " redi at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: clement.chigot at atos dot net @ 2020-09-14  9:07 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 97044
           Summary: Undefined format macros because of include order on
                    AIX
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: clement.chigot at atos dot net
  Target Milestone: ---

On AIX, C++ format macros like "PRIu32" might not be defined even if
"cinttypes" is included. It happends when other headers which have a dependency
on "inttypes.h" are included before. 
On AIX, __STDC_FORMAT_MACROS must be defined before "sys/inttypes.h" is
included in order to have these macros defined. But with for example <cstring>,
as "string.h" includes "sys/types" which included "sys/inttypes.h",
__STDC_FORMAT_MACROS won't be defined when "sys/inttypes.h" is first included
thus the format macros won't be defined. 

This program works on Linux but not on AIX. 
#include <cstring>
#include <cinttypes>
#include <iostream>

int main(){
#ifdef PRIu32
  std::cout << "PRIu32 defined" << std::endl;
#else
  std::cout << "PRIu32 not defined" << std::endl;
#endif
}

My question is what are the G++ standards saying on that ? Should <cinttypes>
always defined "PRIu32"-like macros ? Or does the developers should be careful
the order when are included the headers or always add -D__STDC_FORMAT_MACROS ?  

I would clearly go for one. Especially, because knowing that "#include
<cstring>" must be after "#include <cinttypes>" if you want to use "PRIu32" is 
not obvious. 

Clément

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug libstdc++/97044] Undefined format macros because of include order on AIX
  2020-09-14  9:07 [Bug libstdc++/97044] New: Undefined format macros because of include order on AIX clement.chigot at atos dot net
@ 2020-09-20 20:10 ` redi at gcc dot gnu.org
  2020-09-20 22:18 ` redi at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: redi at gcc dot gnu.org @ 2020-09-20 20:10 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
The C99 standard says that __STDC_FORMATE_MACROS must be defined before
including the header. The C++11 standard is clear that __STDC_FORMAT_MACROS has
no effect in C++ programs, and the header must defined the format macros
unconditionally. AIX apparently follows the C99 rule, even though obviously the
C++ standard defines how C++ works, not C.

This is a bug in the AIX headers.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug libstdc++/97044] Undefined format macros because of include order on AIX
  2020-09-14  9:07 [Bug libstdc++/97044] New: Undefined format macros because of include order on AIX clement.chigot at atos dot net
  2020-09-20 20:10 ` [Bug libstdc++/97044] " redi at gcc dot gnu.org
@ 2020-09-20 22:18 ` redi at gcc dot gnu.org
  2020-09-21  8:13 ` clement.chigot at atos dot net
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: redi at gcc dot gnu.org @ 2020-09-20 22:18 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Specifically, C99 7.8.1 footnote 182 says:

"C++ implementations should define these macros only when _ _STDC_FORMAT_MACROS
is defined before <inttypes.h> is included."

The footnote is not present in C11.

C++11 27.9.2 p3 says:

"Note: The macros defined by <cinttypes> are provided unconditionally. In
particular, the symbol __STDC_FORMAT_MACROS, mentioned in footnote 182 of the C
standard, plays no role in C++."

So requiring the macro to be defined by C++ programs before including
<inttypes.h> is an anachronism that is not compatible with any version of the
C++ standard.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug libstdc++/97044] Undefined format macros because of include order on AIX
  2020-09-14  9:07 [Bug libstdc++/97044] New: Undefined format macros because of include order on AIX clement.chigot at atos dot net
  2020-09-20 20:10 ` [Bug libstdc++/97044] " redi at gcc dot gnu.org
  2020-09-20 22:18 ` redi at gcc dot gnu.org
@ 2020-09-21  8:13 ` clement.chigot at atos dot net
  2020-09-21 12:48 ` dje at gcc dot gnu.org
  2020-09-26 16:01 ` [Bug target/97044] " cvs-commit at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: clement.chigot at atos dot net @ 2020-09-21  8:13 UTC (permalink / raw)
  To: gcc-bugs

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

Clément Chigot <clement.chigot at atos dot net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dje at gcc dot gnu.org

--- Comment #3 from Clément Chigot <clement.chigot at atos dot net> ---
Alright, with David, we came to the same conclusion. Sadly, fixing headers on
AIX will take time and will happen only on newest versions. Thus, using
fixincludes seems the right approach for now. 

Thanks for the explanation.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug libstdc++/97044] Undefined format macros because of include order on AIX
  2020-09-14  9:07 [Bug libstdc++/97044] New: Undefined format macros because of include order on AIX clement.chigot at atos dot net
                   ` (2 preceding siblings ...)
  2020-09-21  8:13 ` clement.chigot at atos dot net
@ 2020-09-21 12:48 ` dje at gcc dot gnu.org
  2020-09-26 16:01 ` [Bug target/97044] " cvs-commit at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: dje at gcc dot gnu.org @ 2020-09-21 12:48 UTC (permalink / raw)
  To: gcc-bugs

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

David Edelsohn <dje at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2020-09-21

--- Comment #4 from David Edelsohn <dje at gcc dot gnu.org> ---
This needs to be fixed with fixincludes.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug target/97044] Undefined format macros because of include order on AIX
  2020-09-14  9:07 [Bug libstdc++/97044] New: Undefined format macros because of include order on AIX clement.chigot at atos dot net
                   ` (3 preceding siblings ...)
  2020-09-21 12:48 ` dje at gcc dot gnu.org
@ 2020-09-26 16:01 ` cvs-commit at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-09-26 16:01 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by David Edelsohn <dje@gcc.gnu.org>:

https://gcc.gnu.org/g:081b3517b4df826ac917147eb906bbb8fc6528b1

commit r11-3482-g081b3517b4df826ac917147eb906bbb8fc6528b1
Author: David Edelsohn <dje.gcc@gmail.com>
Date:   Thu Sep 17 15:18:48 2020 +0000

    aix: Fix _STDC_FORMAT_MACROS in inttypes.h [PR97044]

    AIX protects the STDC Format Macros in a manner that can prevent the
    definition of the macros depending on the order of header inclusion.

    The protection of the macros was referenced in C99, removed in C11, and
    never specified in any C++ standard. Also, the macros are in the namespace
    reserved to the implementation (compiler) so the compiler is permitted to
    choose to inject those names.

    fixincludes/ChangeLog:

    2020-09-17  David Edelsohn  <dje.gcc@gmail.com>

            PR target/97044
            * inclhack.def (aix_inttypes): New fix.
            * fixincl.x: Regenerate.
            * tests/base/sys/inttypes.h: New file.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2020-09-26 16:01 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-14  9:07 [Bug libstdc++/97044] New: Undefined format macros because of include order on AIX clement.chigot at atos dot net
2020-09-20 20:10 ` [Bug libstdc++/97044] " redi at gcc dot gnu.org
2020-09-20 22:18 ` redi at gcc dot gnu.org
2020-09-21  8:13 ` clement.chigot at atos dot net
2020-09-21 12:48 ` dje at gcc dot gnu.org
2020-09-26 16:01 ` [Bug target/97044] " cvs-commit at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).