]> code.ossystems Code Review - openembedded-core.git/blob
15136bfa90bc09e205522adabf4a7a67ff12613f
[openembedded-core.git] /
1 From 87e73453e8135e72f592c1d7c84da942e7a1e308 Mon Sep 17 00:00:00 2001
2 From: jason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
3 Date: Tue, 29 Mar 2011 14:24:59 +0000
4 Subject: [PATCH 026/200]        * decl2.c (cp_check_const_attributes): New.
5         (cplus_decl_attributes): Call cp_check_const_attributes.
6
7 git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/gcc-4_6-branch@171667 138bc75d-0d04-0410-961f-82ee72b054a4
8
9 index eb5d4f5..f62f913 100644
10 --- a/gcc/cp/decl2.c
11 +++ b/gcc/cp/decl2.c
12 @@ -1264,6 +1264,25 @@ cp_reconstruct_complex_type (tree type, tree bottom)
13    return cp_build_qualified_type (outer, cp_type_quals (type));
14  }
15  
16 +/* Replaces any constexpr expression that may be into the attributes
17 +   arguments with their reduced value.  */
18 +
19 +static void
20 +cp_check_const_attributes (tree attributes)
21 +{
22 +  tree attr;
23 +  for (attr = attributes; attr; attr = TREE_CHAIN (attr))
24 +    {
25 +      tree arg;
26 +      for (arg = TREE_VALUE (attr); arg; arg = TREE_CHAIN (arg))
27 +       {
28 +         tree expr = TREE_VALUE (arg);
29 +         if (EXPR_P (expr))
30 +           TREE_VALUE (arg) = maybe_constant_value (expr);
31 +       }
32 +    }
33 +}
34 +
35  /* Like decl_attributes, but handle C++ complexity.  */
36  
37  void
38 @@ -1284,6 +1303,8 @@ cplus_decl_attributes (tree *decl, tree attributes, int flags)
39         return;
40      }
41  
42 +  cp_check_const_attributes (attributes);
43 +
44    if (TREE_CODE (*decl) == TEMPLATE_DECL)
45      decl = &DECL_TEMPLATE_RESULT (*decl);
46  
47 new file mode 100644
48 index 0000000..ac85c07
49 --- /dev/null
50 +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-attribute.C
51 @@ -0,0 +1,63 @@
52 +// { dg-options -std=c++0x }
53 +
54 +//A few constexpr's
55 +constexpr int foo() { return __alignof__(int); }
56 +
57 +template<typename T>
58 +constexpr int fooT() { return __alignof__(T); }
59 +
60 +template<int N>
61 +constexpr int fooN() { return N; }
62 +
63 +//Now the attributes
64 +
65 +//with normal variables,
66 +int a __attribute__((aligned(foo())));
67 +int b __attribute__((aligned(fooT<int>())));
68 +int c __attribute__((aligned(fooN<__alignof__(int)>())));
69 +
70 +//with variables inside a template,
71 +template <typename T>
72 +void fun()
73 +{
74 +    T a __attribute__((aligned(foo())));
75 +    T b __attribute__((aligned(fooT<T>())));
76 +    T c __attribute__((aligned(fooN<__alignof__(T)>())));
77 +    T d __attribute__((aligned(fooT<int>())));
78 +    T e __attribute__((aligned(fooN<__alignof__(int)>())));
79 +}
80 +
81 +//instantiate it,
82 +void bar()
83 +{
84 +    fun<int>();
85 +}
86 +
87 +//with classes
88 +struct __attribute__((aligned(foo()))) S0
89 +{
90 +    char dummy;
91 +};
92 +S0 s0;
93 +
94 +struct __attribute__((aligned(fooT<int>()))) S1
95 +{
96 +    char dummy;
97 +};
98 +S1 s1;
99 +
100 +//and class templates
101 +template <typename T>
102 +struct __attribute__((aligned(foo()))) S2
103 +{
104 +    char dummy;
105 +};
106 +
107 +S2<int> s2;
108 +
109 +template <typename T>
110 +struct __attribute__((aligned(fooT<T>()))) S3
111 +{
112 +    char dummy;
113 +};
114 +S3<int> s3;
115 -- 
116 1.7.0.4
117