aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2013-02-21 02:17:58 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2013-02-21 02:17:58 +0000
commit9f6e9106176008e91af6a974b3cf31c064d6d884 (patch)
treed361537a054e3381c213fb31ee7aade1087eceb6
parent75f6a66f9a946a6839f70cf4856ceb1fb94aa6ad (diff)
libstdc++'s <cstdalign> #includes <stdalign.h> and expects it to guard against
being included in C++. Don't define alignof or alignas in this case. Note that the C++11 standard is broken in various ways here (it refers to the contents of <stdalign.h> in C99, where that header did not exist, and doesn't mention the alignas macro at all), but we do our best to do what it intended. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@175708 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Headers/stdalign.h3
-rw-r--r--test/Headers/cxx11.cpp14
2 files changed, 17 insertions, 0 deletions
diff --git a/lib/Headers/stdalign.h b/lib/Headers/stdalign.h
index 97b18f175b..3738d1284f 100644
--- a/lib/Headers/stdalign.h
+++ b/lib/Headers/stdalign.h
@@ -24,8 +24,11 @@
#ifndef __STDALIGN_H
#define __STDALIGN_H
+#ifndef __cplusplus
#define alignas _Alignas
#define alignof _Alignof
+#endif
+
#define __alignas_is_defined 1
#define __alignof_is_defined 1
diff --git a/test/Headers/cxx11.cpp b/test/Headers/cxx11.cpp
new file mode 100644
index 0000000000..995fc6528d
--- /dev/null
+++ b/test/Headers/cxx11.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang -fsyntax-only -std=c++11 %s
+
+#include <stdalign.h>
+
+#if defined alignas
+#error alignas should not be defined in C++
+#endif
+
+#if defined alignof
+#error alignof should not be defined in C++
+#endif
+
+static_assert(__alignas_is_defined, "");
+static_assert(__alignof_is_defined, "");