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

Howard Hinnant hhinnant at apple.com
Thu Jul 26 12:48:10 PDT 2012


Could you create a patch for CREDITS.TXT?

Thanks,
Howard

On Jul 26, 2012, at 3:25 PM, "Andrew C. Morrow" <andrew.c.morrow at gmail.com> wrote:

> 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
> <libc++.stdio.getc.putc.patch>_______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits




More information about the cfe-commits mailing list