Skip to content

Commit

Permalink
libstdc++'s <cstdalign> #includes <stdalign.h> and expects it to guar…
Browse files Browse the repository at this point in the history
…d 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.

llvm-svn: 175708
  • Loading branch information
zygoloid committed Feb 21, 2013
1 parent dc46338 commit 8acb404
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
3 changes: 3 additions & 0 deletions clang/lib/Headers/stdalign.h
Expand Up @@ -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

Expand Down
14 changes: 14 additions & 0 deletions clang/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, "");

0 comments on commit 8acb404

Please sign in to comment.