<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Mon, Oct 12, 2015 at 9:41 AM, Steven Wu via cfe-commits <span dir="ltr"><<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Richard<br>
<br>
Your splitting seems causing problem when using extern "C". Here is a test case:<br>
<br>
$ cat test.cpp<br>
#ifdef __cplusplus<br>
extern "C" {<br>
#endif<br>
#include <stdio.h><br>
#ifdef __cplusplus<br>
}<br>
#endif<br>
<br>
Error:<br>
clang -fsyntax-only test.cpp<br>
In file included from test.cpp:4:<br>
In file included from /usr/bin/../include/c++/v1/stdio.h:102:<br>
/usr/bin/../include/c++/v1/__config:593:1: error:<br>
      templates must have C++ linkage<br>
template <bool> struct __static_assert_test;<br>
^~~~~~~~~~~~~~~<br>
/usr/bin/../include/c++/v1/__config:594:20: error:<br>
      explicit specialization of non-template struct '__static_assert_test'<br>
template <> struct __static_assert_test<true> {};<br>
                   ^                   ~~~~~~<br>
/usr/bin/../include/c++/v1/__config:595:1: error:<br>
      templates must have C++ linkage<br>
template <unsigned> struct __static_assert_check {};<br>
^~~~~~~~~~~~~~~~~~~<br>
3 errors generated.<br>
<br>
Because the code is actually compiled in C++, the guard in the header failed to exclude the templates. In the meantime, I don't know if there are ways to detect the header is in extern "C".<br></blockquote><div><br></div><div>This was supposed to work, but apparently I only tested it when compiling as C++11; the static_assert emulation in C++98 mode needs some massaging to cope with this.</div><div><br></div><div>Eric, Marshall: Are you OK with the attached patch? The idea is to make <__config> be fine to include in extern "C" or extern "C++" modes (and likewise for the <foo.h> headers). This is something that comes up pretty often in practice (people wrap an include of a C header in 'extern "C"', and that C header includes a <foo.h> file that libc++ provides).</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Steven<br>
<div class="HOEnZb"><div class="h5"><br>
<br>
> On Oct 8, 2015, at 6:29 PM, Richard Smith via cfe-commits <<a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a>> wrote:<br>
><br>
> Author: rsmith<br>
> Date: Thu Oct  8 20:29:09 2015<br>
> New Revision: 249798<br>
><br>
> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=249798&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=249798&view=rev</a><br>
> Log:<br>
> Split <stdio.h> out of <cstdio>.<br>
><br>
> As with <stddef.h>, skip our custom header if __need_FILE or __need___FILE is defined.<br>
><br>
> Added:<br>
>    libcxx/trunk/include/stdio.h<br>
>      - copied, changed from r249736, libcxx/trunk/include/cstdio<br>
> Modified:<br>
>    libcxx/trunk/include/cstdio<br>
>    libcxx/trunk/test/std/depr/depr.c.headers/stdio_h.pass.cpp<br>
><br>
> Modified: libcxx/trunk/include/cstdio<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/cstdio?rev=249798&r1=249797&r2=249798&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/cstdio?rev=249798&r1=249797&r2=249798&view=diff</a><br>
> ==============================================================================<br>
> --- libcxx/trunk/include/cstdio (original)<br>
> +++ libcxx/trunk/include/cstdio Thu Oct  8 20:29:09 2015<br>
> @@ -103,16 +103,6 @@ void perror(const char* s);<br>
> #pragma GCC system_header<br>
> #endif<br>
><br>
> -// snprintf<br>
> -#if defined(_LIBCPP_MSVCRT)<br>
> -#include "support/win32/support.h"<br>
> -#endif<br>
> -<br>
> -#undef getc<br>
> -#undef putc<br>
> -#undef clearerr<br>
> -#undef feof<br>
> -#undef ferror<br>
> _LIBCPP_BEGIN_NAMESPACE_STD<br>
><br>
> using ::FILE;<br>
><br>
> Copied: libcxx/trunk/include/stdio.h (from r249736, libcxx/trunk/include/cstdio)<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/stdio.h?p2=libcxx/trunk/include/stdio.h&p1=libcxx/trunk/include/cstdio&r1=249736&r2=249798&rev=249798&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/stdio.h?p2=libcxx/trunk/include/stdio.h&p1=libcxx/trunk/include/cstdio&r1=249736&r2=249798&rev=249798&view=diff</a><br>
> ==============================================================================<br>
> --- libcxx/trunk/include/cstdio (original)<br>
> +++ libcxx/trunk/include/stdio.h Thu Oct  8 20:29:09 2015<br>
> @@ -1,5 +1,5 @@<br>
> // -*- C++ -*-<br>
> -//===---------------------------- cstdio ----------------------------------===//<br>
> +//===---------------------------- stdio.h ---------------------------------===//<br>
> //<br>
> //                     The LLVM Compiler Infrastructure<br>
> //<br>
> @@ -8,11 +8,19 @@<br>
> //<br>
> //===----------------------------------------------------------------------===//<br>
><br>
> -#ifndef _LIBCPP_CSTDIO<br>
> -#define _LIBCPP_CSTDIO<br>
> +#if defined(__need_FILE) || defined(__need___FILE)<br>
> +<br>
> +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)<br>
> +#pragma GCC system_header<br>
> +#endif<br>
> +<br>
> +#include_next <stdio.h><br>
> +<br>
> +#elif !defined(_LIBCPP_STDIO_H)<br>
> +#define _LIBCPP_STDIO_H<br>
><br>
> /*<br>
> -    cstdio synopsis<br>
> +    stdio.h synopsis<br>
><br>
> Macros:<br>
><br>
> @@ -33,9 +41,6 @@ Macros:<br>
>     stdin<br>
>     stdout<br>
><br>
> -namespace std<br>
> -{<br>
> -<br>
> Types:<br>
><br>
> FILE<br>
> @@ -92,20 +97,23 @@ void clearerr(FILE* stream);<br>
> int feof(FILE* stream);<br>
> int ferror(FILE* stream);<br>
> void perror(const char* s);<br>
> -<br>
> -}  // std<br>
> */<br>
><br>
> #include <__config><br>
> -#include <stdio.h><br>
><br>
> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)<br>
> #pragma GCC system_header<br>
> #endif<br>
><br>
> +#include_next <stdio.h><br>
> +<br>
> +#ifdef __cplusplus<br>
> +<br>
> // snprintf<br>
> #if defined(_LIBCPP_MSVCRT)<br>
> +extern "C++" {<br>
> #include "support/win32/support.h"<br>
> +}<br>
> #endif<br>
><br>
> #undef getc<br>
> @@ -113,72 +121,7 @@ void perror(const char* s);<br>
> #undef clearerr<br>
> #undef feof<br>
> #undef ferror<br>
> -_LIBCPP_BEGIN_NAMESPACE_STD<br>
> -<br>
> -using ::FILE;<br>
> -using ::fpos_t;<br>
> -using ::size_t;<br>
> -<br>
> -using ::fclose;<br>
> -using ::fflush;<br>
> -using ::setbuf;<br>
> -using ::setvbuf;<br>
> -using ::fprintf;<br>
> -using ::fscanf;<br>
> -using ::snprintf;<br>
> -using ::sprintf;<br>
> -using ::sscanf;<br>
> -#ifndef _LIBCPP_MSVCRT<br>
> -using ::vfprintf;<br>
> -using ::vfscanf;<br>
> -using ::vsscanf;<br>
> -#endif // _LIBCPP_MSVCRT<br>
> -using ::vsnprintf;<br>
> -using ::vsprintf;<br>
> -using ::fgetc;<br>
> -using ::fgets;<br>
> -using ::fputc;<br>
> -using ::fputs;<br>
> -using ::getc;<br>
> -using ::putc;<br>
> -using ::ungetc;<br>
> -using ::fread;<br>
> -using ::fwrite;<br>
> -using ::fgetpos;<br>
> -using ::fseek;<br>
> -using ::fsetpos;<br>
> -using ::ftell;<br>
> -using ::rewind;<br>
> -using ::clearerr;<br>
> -using ::feof;<br>
> -using ::ferror;<br>
> -using ::perror;<br>
> -<br>
> -#ifndef _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE<br>
> -using ::fopen;<br>
> -using ::freopen;<br>
> -using ::remove;<br>
> -using ::rename;<br>
> -using ::tmpfile;<br>
> -using ::tmpnam;<br>
> -#endif<br>
><br>
> -#ifndef _LIBCPP_HAS_NO_STDIN<br>
> -using ::getchar;<br>
> -#if _LIBCPP_STD_VER <= 11<br>
> -using ::gets;<br>
> #endif<br>
> -using ::scanf;<br>
> -using ::vscanf;<br>
> -#endif<br>
> -<br>
> -#ifndef _LIBCPP_HAS_NO_STDOUT<br>
> -using ::printf;<br>
> -using ::putchar;<br>
> -using ::puts;<br>
> -using ::vprintf;<br>
> -#endif<br>
> -<br>
> -_LIBCPP_END_NAMESPACE_STD<br>
><br>
> -#endif  // _LIBCPP_CSTDIO<br>
> +#endif  // _LIBCPP_STDIO_H<br>
><br>
> Modified: libcxx/trunk/test/std/depr/depr.c.headers/stdio_h.pass.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/depr/depr.c.headers/stdio_h.pass.cpp?rev=249798&r1=249797&r2=249798&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/depr/depr.c.headers/stdio_h.pass.cpp?rev=249798&r1=249797&r2=249798&view=diff</a><br>
> ==============================================================================<br>
> --- libcxx/trunk/test/std/depr/depr.c.headers/stdio_h.pass.cpp (original)<br>
> +++ libcxx/trunk/test/std/depr/depr.c.headers/stdio_h.pass.cpp Thu Oct  8 20:29:09 2015<br>
> @@ -13,6 +13,26 @@<br>
> #include <type_traits><br>
> #include "test_macros.h"<br>
><br>
> +#ifdef getc<br>
> +#error getc is defined<br>
> +#endif<br>
> +<br>
> +#ifdef putc<br>
> +#error putc is defined<br>
> +#endif<br>
> +<br>
> +#ifdef clearerr<br>
> +#error clearerr is defined<br>
> +#endif<br>
> +<br>
> +#ifdef feof<br>
> +#error feof is defined<br>
> +#endif<br>
> +<br>
> +#ifdef ferror<br>
> +#error ferror is defined<br>
> +#endif<br>
> +<br>
> #ifndef BUFSIZ<br>
> #error BUFSIZ not defined<br>
> #endif<br>
><br>
><br>
> _______________________________________________<br>
> cfe-commits mailing list<br>
> <a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a><br>
> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits</a><br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits</a><br>
</div></div></blockquote></div><br></div></div>