[cfe-commits] [libc++][patch] shims to work around macroized getc and putc on linux

Andrew C. Morrow andrew.c.morrow at gmail.com
Thu Jul 26 12:25:39 PDT 2012


On my eglibc 2.13 based Debian system 'getc' is a macro defined in
/usr/include/stdio.h. This decision to make it a macro doesn't seem to
be guarded by any feature test macro as far as I can see:

/* The C standard explicitly says this is a macro, so we always do the
   optimization for it.  */
#define getc(_fp) _IO_getc (_fp)

The same is true for 'putc'.

Having theses as macros breaks
test/input.output/file.streams/c.files/cstdio.pass.cpp:

test/input.output/file.streams/c.files/cstdio.pass.cpp:119:47: error:
no member named '_IO_getc' in namespace 'std'
    static_assert((std::is_same<decltype(std::getc(fp)), int>::value), "");
                                         ~~~~~^
/usr/include/stdio.h:545:19: note: expanded from macro 'getc'
#define getc(_fp) _IO_getc (_fp)

and:

input.output/file.streams/c.files/cstdio.pass.cpp:122:47: error: no
member named '_IO_putc' in namespace 'std'
    static_assert((std::is_same<decltype(std::putc(0,fp)), int>::value), "");
                                         ~~~~~^
/usr/include/stdio.h:587:24: note: expanded from macro 'putc'
#define putc(_ch, _fp) _IO_putc (_ch, _fp)

I've attached a patch that fixes this by adding __libcpp_ style shims
for getc and putc at global scope in include/cstdio. If there is a way
to avoid needing to do this or a better approach I'm all for it.

Thanks,
Andrew
-------------- next part --------------
A non-text attachment was scrubbed...
Name: libc++.stdio.getc.putc.patch
Type: application/octet-stream
Size: 755 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20120726/e3283179/attachment.obj>


More information about the cfe-commits mailing list