summaryrefslogtreecommitdiff
path: root/libs/glibmm2/scripts/cxx.m4
blob: 8dce019940923ee7fd98631edfc174ea0ec8ba70 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364

dnl
dnl AC_CXX_NAMESPACES(ACTION_FOUND,ACTION_NOT_FOUND)
dnl
AC_DEFUN([AC_CXX_NAMESPACES],[
AC_MSG_CHECKING(if C++ compiler supports namespaces)
AC_TRY_COMPILE(
[
namespace Foo { struct A {}; }
using namespace Foo;
],[
A a;
(void)a;
],[
 ac_cxx_namespaces=yes
 AC_MSG_RESULT([$ac_cxx_namespaces])
 $1
],[
 ac_cxx_namespaces=no
 AC_MSG_RESULT([$ac_cxx_namespaces])
 $2
])
])

dnl
dnl AC_CXX_NAMESPACES(ACTION_FOUND,ACTION_NOT_FOUND)
dnl
AC_DEFUN([AC_CXX_BOOL],[
AC_MSG_CHECKING(if C++ compiler supports bool)
AC_TRY_COMPILE(
[
],[
   bool b=true;
   bool b1=false;
   (void)b;
   (void)b1;
],[
  ac_cxx_bool=yes
  AC_MSG_RESULT([$ac_cxx_bool])
  $1
],[
  ac_cxx_bool=no
  AC_MSG_RESULT([$ac_cxx_bool])
  $2
])
])

dnl
dnl AC_CXX_MUTABLE(ACTION_FOUND,ACTION_NOT_FOUND)
dnl
AC_DEFUN([AC_CXX_MUTABLE],[
AC_MSG_CHECKING(if C++ compiler supports mutable)
AC_TRY_COMPILE(
[
class k {   
  mutable char *c;
public:
   void foo() const { c=0; }
};
],[
],[
  ac_cxx_mutable=yes
  AC_MSG_RESULT([$ac_cxx_mutable])
  $1
],[
  ac_cxx_mutable=no
  AC_MSG_RESULT([$ac_cxx_mutable])
  $2
]) 
])


dnl
dnl AC_CXX_CONST_CAST(ACTION_FOUND,ACTION_NOT_FOUND)
dnl
AC_DEFUN([AC_CXX_CONST_CAST],[
AC_MSG_CHECKING([if C++ compiler supports const_cast<>])
AC_TRY_COMPILE(
[
   class foo;
],[
   const foo *c=0;
   foo *c1=const_cast<foo*>(c);
   (void)c1;
],[
  ac_cxx_const_cast=yes
  AC_MSG_RESULT([$ac_cxx_const_cast])
],[
  ac_cxx_const_cast=no
  AC_MSG_RESULT([$ac_cxx_const_cast])
])
])


dnl
dnl GLIBMM_CXX_MEMBER_FUNCTIONS_MEMBER_TEMPLATES(ACTION_FOUND,ACTION_NOT_FOUND)
dnl
dnl Test whether the compiler allows member functions to refer to spezialized member function templates.
dnl Some compilers have problems with this. gcc 2.95.3 aborts with an internal compiler error.
dnl
AC_DEFUN([GLIBMM_CXX_MEMBER_FUNCTIONS_MEMBER_TEMPLATES],[
AC_MSG_CHECKING([if C++ compiler allows member functions to refer to member templates])
AC_TRY_COMPILE(
[
  struct foo {
    template <class C> inline
    void doit();
    void thebug();
  };

  template <class C> inline
  void foo::doit() {
  }

  struct bar {
    void neitherabug();
  };

  void notabug() {
    void (foo::*func)();
    func = &foo::doit<int>;
    (void)func;
  }

  void bar::neitherabug() {
    void (foo::*func)();
    func = &foo::doit<int>;
    (void)func;
  }

  void foo::thebug() {
    void (foo::*func)();
    func = &foo::doit<int>; //Compiler bugs usually show here.
    (void)func;
  }
],[],[
  glibmm_cxx_member_functions_member_templates=yes
  AC_DEFINE([GLIBMM_MEMBER_FUNCTIONS_MEMBER_TEMPLATES],[1],[does the C++ compiler allow member functions to refer to member templates])
  AC_MSG_RESULT([$glibmm_cxx_member_functions_member_templates])
],[
  glibmm_cxx_member_functions_member_templates=no
  AC_DEFINE([GLIBMM_MEMBER_FUNCTIONS_MEMBER_TEMPLATES],[0])
  AC_MSG_RESULT([$glibmm_cxx_member_functions_member_templates])
])
])

## GLIBMM_CXX_CAN_DISAMBIGUATE_CONST_TEMPLATE_SPECIALIZATIONS()
##
## Check whether the compiler finds it ambiguous to have both
## const and non-const template specializations,
## The SUN Forte compiler has this problem, though we are
## not 100% sure that it's a C++ standards violation.
##
AC_DEFUN([GLIBMM_CXX_CAN_DISAMBIGUATE_CONST_TEMPLATE_SPECIALIZATIONS],
[
  AC_REQUIRE([GLIBMM_CXX_HAS_NAMESPACE_STD])

  AC_CACHE_CHECK(
    [whether the compiler finds it ambiguous to have both const and non-const template specializations],
    [glibmm_cv_cxx_can_disambiguate_const_template_specializations],
  [
    AC_TRY_COMPILE(
    [
      #include <iostream>

      template <class T> class Foo {};

      template <typename T> class Traits {
      public:
          const char* whoami() {
              return "generic template";
          }
      };

      template <typename T> class Traits<Foo<T> > {
      public:
          const char* whoami() {
              return "partial specialization for Foo<T>";
          }
      };

      template <typename T> class Traits<Foo<const T> > {
      public:
          const char* whoami() {
              return "partial specialization for Foo<const T>";
          }
      };
      
    ],[
          Traits<int> it;
          Traits<Foo<int> > fit;
          Traits<Foo<const int> > cfit;

          std::cout << "Traits<int>             --> "
                    << it.whoami() << std::endl;
          std::cout << "Traits<Foo<int>>        --> "
                    << fit.whoami() << std::endl;
          std::cout << "Traits<Foo<const int >> --> "
                    << cfit.whoami() << std::endl;
    ],
      [glibmm_cv_cxx_can_disambiguate_const_template_specializations="yes"],
      [glibmm_cv_cxx_can_disambiguate_const_template_specializations="no"]
    )
  ])

  if test "x${glibmm_cv_cxx_can_disambiguate_const_template_specializations}" = "xyes"; then
  {
    AC_DEFINE([GLIBMM_HAVE_DISAMBIGUOUS_CONST_TEMPLATE_SPECIALIZATIONS],[1], [Defined if the compiler does not find it ambiguous to have both const and non-const template specializations])
  }
  fi
])



## GLIBMM_CXX_CAN_USE_DYNAMIC_CAST_IN_UNUSED_TEMPLATE_WITHOUT_DEFINITION()
##
## Check whether the compiler allows us to define a template that uses 
## dynamic_cast<> with an object whose type is not defined, 
## even if we do not use that template before we have defined the type.
## This should probably not be allowed anyway.
##
AC_DEFUN([GLIBMM_CXX_CAN_USE_DYNAMIC_CAST_IN_UNUSED_TEMPLATE_WITHOUT_DEFINITION],
[
  AC_CACHE_CHECK(
    [whether the compiler allows us to define a template that uses dynamic_cast<> with an object whose type is not yet defined],
    [glibmm_cv_cxx_can_use_dynamic_cast_in_unused_template_without_definition],
  [
    AC_TRY_COMPILE(
    [
      class SomeClass;

      SomeClass* some_function();

      template <class T>
      class SomeTemplate
      {
        static bool do_something()
        {
          //This does not compile, with the MipsPro (IRIX) compiler
          //even if we don't use this template at all.
          //(We would use it later, after we have defined the type).
          return dynamic_cast<T*>(some_function());
        }
      };
      
    ],[
       
    ],
      [glibmm_cv_cxx_can_use_dynamic_cast_in_unused_template_without_definition="yes"],
      [glibmm_cv_cxx_can_use_dynamic_cast_in_unused_template_without_definition="no"]
    )
  ])

  if test "x${glibmm_cv_cxx_can_use_dynamic_cast_in_unused_template_without_definition}" = "xyes"; then
  {
    AC_DEFINE([GLIBMM_CAN_USE_DYNAMIC_CAST_IN_UNUSED_TEMPLATE_WITHOUT_DEFINITION],[1], [Defined if the compiler allows us to define a template that uses dynamic_cast<> with an object whose type is not yet defined.])
  }
  fi
])


## GLIBMM_CXX_CAN_ASSIGN_NON_EXTERN_C_FUNCTIONS_TO_EXTERN_C_CALLBACKS()
##
## Check whether the compiler allows us to use a non-extern "C" function, 
## such as a static member function, to an extern "C" function pointer, 
## such as a GTK+ callback.
## This should not be allowed anyway.
##
AC_DEFUN([GLIBMM_CXX_CAN_ASSIGN_NON_EXTERN_C_FUNCTIONS_TO_EXTERN_C_CALLBACKS],
[
  AC_CACHE_CHECK(
    [whether the the compilerallows us to use a non-extern "C" function for an extern "C" function pointer.],
    [glibmm_cv_cxx_can_assign_non_extern_c_functions_to_extern_c_callbacks],
  [
    AC_TRY_COMPILE(
    [
      extern "C"
      {
        struct somestruct
        {
          void (*callback) (int);
        };
        
      } // extern "C"
      
      void somefunction(int)
      {
      }
      
    ],[ 
      somestruct something;
      something.callback = &somefunction;
    ],
      [glibmm_cv_cxx_can_assign_non_extern_c_functions_to_extern_c_callbacks="yes"],
      [glibmm_cv_cxx_can_assign_non_extern_c_functions_to_extern_c_callbacks="no"]
    )
  ])

  if test "x${glibmm_cv_cxx_can_assign_non_extern_c_functions_to_extern_c_callbacks}" = "xyes"; then
  {
    AC_DEFINE([GLIBMM_CAN_ASSIGN_NON_EXTERN_C_FUNCTIONS_TO_EXTERN_C_CALLBACKS],[1], [Defined if the compiler allows us to use a non-extern "C" function for an extern "C" function pointer.])
  }
  fi
])

## GLIBMM_CXX_CAN_USE_NAMESPACES_INSIDE_EXTERNC()
##
## Check whether the compiler puts extern "C" functions in the global namespace, 
## even inside a namespace declaration. The AIX xlC compiler does this, and also 
## gets confused if we declare the namespace again inside the extern "C" block.
## This seems like a compiler bug, but not a serious one.
##
AC_DEFUN([GLIBMM_CXX_CAN_USE_NAMESPACES_INSIDE_EXTERNC],
[
  AC_CACHE_CHECK(
    [whether the compiler uses namespace declarations inside extern "C" blocks.],
    [glibmm_cv_cxx_can_use_namespaces_inside_externc],
  [
    AC_TRY_COMPILE(
    [
      namespace test
      {
      
      extern "C"
      {
      
      void do_something();
      
      } //extern C
      
      
      class Something
      {
      protected:
        int i;
      
        friend void do_something();
      };
      
      void do_something()
      {
        Something something;
        something.i = 1;
      }
      
      } //namespace

      
    ],[ 
     
    ],
      [glibmm_cv_cxx_can_use_namespaces_inside_externc="yes"],
      [glibmm_cv_cxx_can_use_namespaces_inside_externc="no"]
    )
  ])

  if test "x${glibmm_cv_cxx_can_use_namespaces_inside_externc}" = "xyes"; then
  {
    AC_DEFINE([GLIBMM_CAN_USE_NAMESPACES_INSIDE_EXTERNC],[1], [Defined if the compiler whether the compiler uses namespace declarations inside extern "C" blocks.])
  }
  fi
])