public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libc/17082] New: htons et al.: statement-expressions prevent use on global scope with -O1 and higher
@ 2014-06-23 19:53 jh_sourceware.org at sotun dot de
  2014-06-23 20:10 ` [Bug libc/17082] " joseph at codesourcery dot com
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: jh_sourceware.org at sotun dot de @ 2014-06-23 19:53 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=17082

            Bug ID: 17082
           Summary: htons et al.: statement-expressions prevent use on
                    global scope with -O1 and higher
           Product: glibc
           Version: unspecified
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: libc
          Assignee: unassigned at sourceware dot org
          Reporter: jh_sourceware.org at sotun dot de
                CC: drepper.fsp at gmail dot com

htons() and many other libc functions are implemented using macros with
statement-expressions when compiled with -O1 or higher. Statement-expressions
are not supported on global scope in GCC, resulting in a compilation failure of
code like

> cat test.cpp
#include <netinet/in.h>
in_port_t p = htons(42);
> g++ test.cpp -O1
test.cpp:2:15: error: statement-expressions are not allowed outside functions
nor in template-argument lists

This seems to be a design decision for a manual optimization; and against
supporting the rare case of complex code on global scope.

It may be time to reevaluate that decision:
1. Small functions can be reliably inlined, optimizing away instructions that
otherwise would have been prevented using macros.
2. C++ lambda functions are on the rise. They allowing several nice patterns
with global scope code (e.g. for data structure initialization). But
statement-expressions do not work in lambdas defined on global scope. Their
prevalence in glibc complicates said patterns and causes confusing error
messages when moving code between function and global scope.

Implementing user-visible libc functions as functions instead of macros solves
this problem.

-- 
You are receiving this mail because:
You are on the CC list for the bug.


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

* [Bug libc/17082] htons et al.: statement-expressions prevent use on global scope with -O1 and higher
  2014-06-23 19:53 [Bug libc/17082] New: htons et al.: statement-expressions prevent use on global scope with -O1 and higher jh_sourceware.org at sotun dot de
@ 2014-06-23 20:10 ` joseph at codesourcery dot com
  2014-06-24  7:40 ` fweimer at redhat dot com
  2015-03-15  7:59 ` cemkalyoncu at gmail dot com
  2 siblings, 0 replies; 4+ messages in thread
From: joseph at codesourcery dot com @ 2014-06-23 20:10 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=17082

--- Comment #1 from joseph at codesourcery dot com <joseph at codesourcery dot com> ---
Policy questions should best be taken to libc-alpha (by someone willing to 
take the lead in getting the discussion to consensus and then documenting 
the resulting consensus on the wiki, not just posting a one-off question 
and waiting for an answer to emerge) rather than filed as bugs; Bugzilla 
is best for something where the presence of a defect is unambiguous under 
existing policy.  If such a consensus were in the direction you propose, 
any bugs filed should be separate bugs for each function or header 
involved so it is clear what is or is not fixed rather than needing to 
track some bugs as partly fixed.

-- 
You are receiving this mail because:
You are on the CC list for the bug.


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

* [Bug libc/17082] htons et al.: statement-expressions prevent use on global scope with -O1 and higher
  2014-06-23 19:53 [Bug libc/17082] New: htons et al.: statement-expressions prevent use on global scope with -O1 and higher jh_sourceware.org at sotun dot de
  2014-06-23 20:10 ` [Bug libc/17082] " joseph at codesourcery dot com
@ 2014-06-24  7:40 ` fweimer at redhat dot com
  2015-03-15  7:59 ` cemkalyoncu at gmail dot com
  2 siblings, 0 replies; 4+ messages in thread
From: fweimer at redhat dot com @ 2014-06-24  7:40 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=17082

Florian Weimer <fweimer at redhat dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
              Flags|                            |security-

-- 
You are receiving this mail because:
You are on the CC list for the bug.


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

* [Bug libc/17082] htons et al.: statement-expressions prevent use on global scope with -O1 and higher
  2014-06-23 19:53 [Bug libc/17082] New: htons et al.: statement-expressions prevent use on global scope with -O1 and higher jh_sourceware.org at sotun dot de
  2014-06-23 20:10 ` [Bug libc/17082] " joseph at codesourcery dot com
  2014-06-24  7:40 ` fweimer at redhat dot com
@ 2015-03-15  7:59 ` cemkalyoncu at gmail dot com
  2 siblings, 0 replies; 4+ messages in thread
From: cemkalyoncu at gmail dot com @ 2015-03-15  7:59 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=17082

Cem Kalyoncu <cemkalyoncu at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |cemkalyoncu at gmail dot com

-- 
You are receiving this mail because:
You are on the CC list for the bug.


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

end of thread, other threads:[~2015-03-15  7:59 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-06-23 19:53 [Bug libc/17082] New: htons et al.: statement-expressions prevent use on global scope with -O1 and higher jh_sourceware.org at sotun dot de
2014-06-23 20:10 ` [Bug libc/17082] " joseph at codesourcery dot com
2014-06-24  7:40 ` fweimer at redhat dot com
2015-03-15  7:59 ` cemkalyoncu at gmail dot com

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).