Bug 3440 - locale.h macros like LC_ALL are not usable in #if
Summary: locale.h macros like LC_ALL are not usable in #if
Alias: None
Product: glibc
Classification: Unclassified
Component: libc (show other bugs)
Version: unspecified
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
Depends on:
Reported: 2006-10-31 20:08 UTC by Paul Eggert
Modified: 2016-05-08 14:15 UTC (History)
1 user (show)

See Also:
Last reconfirmed:
fweimer: security-

patch for LC_ALL etc. to be usable in #if (716 bytes, patch)
2006-10-31 20:09 UTC, Paul Eggert
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Paul Eggert 2006-10-31 20:08:34 UTC
Geoff Clare reported some conformance issues with glibc headers that
define some macros using techniques that do not work inside #if, even
though C99 and POSIX require that the macros work in #if.  I recently
reported some of them against the math component (glibc bug 3439).
locale.h has some issues too, though, with macros like LC_ALL.

I'll attach an (untested but obvious) patch against glibc head.
Comment 1 Paul Eggert 2006-10-31 20:09:44 UTC
Created attachment 1396 [details]
patch for LC_ALL etc. to be usable in #if
Comment 2 Ulrich Drepper 2006-11-10 16:24:22 UTC
I don't want to change this.  It's a pointless requirement which just makes it
harder to debug programs since the macros might not be available in the debug info.

Comment 3 Paul Eggert 2006-11-10 19:06:35 UTC
But this patch does not make it harder to debug programs, since it is already
the case that macros like LC_ALL are typically unavailable in the debug info.
<locale.h> has "#define LC_ALL __LC_ALL", and unless you use something like
gcc -g3, gdb won't see the LC_ALL.

If you like, I can rework the patch so that macros like __LC_ALL are
available in the debug info, but I doubt whether any normal users would
care so I don't see the point.

A better possibility is to rework this patch so that LC_ALL is typically
available in the debug info, while still conforming to C99 and POSIX.
This would require changing locale.h as well.  I can submit that patch
if you prefer.

(The patches for math.h and fenv.h -- bug 3439 -- are in a different category;
I'll look at them a bit later.)
Comment 4 Ulrich Drepper 2007-02-17 08:59:42 UTC
More of this macro nonsense.
Comment 5 Joseph Myers 2012-04-27 10:50:20 UTC
Reopening.  We discussed this general issue on #glibc last night.  Paul, could you update your patch for current glibc and send it to libc-alpha for review?

(Note: I have not checked if any standard C headers other than those mentioned in this bug and bug 3439 are affected by similar issues.  And I have not checked if POSIX has the same requirement for integer constant expression macros in POSIX headers, or what bugs there might be in POSIX headers if so.)
Comment 6 Joseph Myers 2012-05-10 12:41:52 UTC
Fixed by:

commit 02467e1ca1745158c99c9b2576b05850028394f7
Author: Paul Eggert <eggert@cs.ucla.edu>
Date:   Thu May 10 12:38:09 2012 +0000

    [PATCH] [BZ #3440] Make LC_ALL etc. useful in #if expressions.