r175708 - libstdc++'s <cstdalign> #includes <stdalign.h> and expects it to guard against

Richard Smith richard-llvm at metafoo.co.uk
Wed Feb 20 18:17:58 PST 2013


Author: rsmith
Date: Wed Feb 20 20:17:58 2013
New Revision: 175708

URL: http://llvm.org/viewvc/llvm-project?rev=175708&view=rev
Log:
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.

Added:
    cfe/trunk/test/Headers/cxx11.cpp
Modified:
    cfe/trunk/lib/Headers/stdalign.h

Modified: cfe/trunk/lib/Headers/stdalign.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/stdalign.h?rev=175708&r1=175707&r2=175708&view=diff
==============================================================================
--- cfe/trunk/lib/Headers/stdalign.h (original)
+++ cfe/trunk/lib/Headers/stdalign.h Wed Feb 20 20:17:58 2013
@@ -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
 

Added: cfe/trunk/test/Headers/cxx11.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Headers/cxx11.cpp?rev=175708&view=auto
==============================================================================
--- cfe/trunk/test/Headers/cxx11.cpp (added)
+++ cfe/trunk/test/Headers/cxx11.cpp Wed Feb 20 20:17:58 2013
@@ -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, "");





More information about the cfe-commits mailing list