summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2015-10-13 23:12:22 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2015-10-13 23:12:22 +0000
commitf157e47fb81d4d70f018e692f28e62ca6a65c320 (patch)
treee775e9930362e5fd1adb1b482164da72bd2dae1e
parent658beb930e5b637253fe6b2aa071a830ec0431e1 (diff)
downloadbcm5719-llvm-f157e47fb81d4d70f018e692f28e62ca6a65c320.tar.gz
bcm5719-llvm-f157e47fb81d4d70f018e692f28e62ca6a65c320.zip
Fix use of libc++ <foo.h> headers from within an 'extern "C"' context in C++98.
Previously, this resulted in us declaring a template for static_assert emulation within the 'extern "C"' context, which is ill-formed. llvm-svn: 250247
-rw-r--r--libcxx/include/__config2
-rw-r--r--libcxx/test/std/depr/depr.c.headers/extern_c.pass.cpp43
2 files changed, 45 insertions, 0 deletions
diff --git a/libcxx/include/__config b/libcxx/include/__config
index 73e653c1990..a11dbc96dfe 100644
--- a/libcxx/include/__config
+++ b/libcxx/include/__config
@@ -591,9 +591,11 @@ typedef unsigned int char32_t;
#ifdef _LIBCPP_HAS_NO_STATIC_ASSERT
+extern "C++" {
template <bool> struct __static_assert_test;
template <> struct __static_assert_test<true> {};
template <unsigned> struct __static_assert_check {};
+}
#define static_assert(__b, __m) \
typedef __static_assert_check<sizeof(__static_assert_test<(__b)>)> \
_LIBCPP_CONCAT(__t, __LINE__)
diff --git a/libcxx/test/std/depr/depr.c.headers/extern_c.pass.cpp b/libcxx/test/std/depr/depr.c.headers/extern_c.pass.cpp
new file mode 100644
index 00000000000..d4d8b5fafdd
--- /dev/null
+++ b/libcxx/test/std/depr/depr.c.headers/extern_c.pass.cpp
@@ -0,0 +1,43 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// Sometimes C++'s <foo.h> headers get included within extern "C" contexts. This
+// is ill-formed (no diagnostic required), per [using.headers]p3, but we permit
+// it as an extension.
+
+extern "C" {
+#include <assert.h>
+// complex.h is not supported in extern "C".
+#include <ctype.h>
+#include <errno.h>
+#include <fenv.h>
+#include <float.h>
+#include <inttypes.h>
+#include <iso646.h>
+#include <limits.h>
+#include <locale.h>
+#include <math.h>
+#include <setjmp.h>
+#include <signal.h>
+#include <stdalign.h>
+#include <stdarg.h>
+#include <stdbool.h>
+#include <stddef.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+// tgmath.h is not supported in extern "C".
+#include <time.h>
+// FIXME: #include <uchar.h>
+#include <wchar.h>
+#include <wctype.h>
+}
+
+int main() {}
OpenPOWER on IntegriCloud