File: addressof_test.cpp

package info (click to toggle)
boost 1.32.0-6
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 93,952 kB
  • ctags: 128,458
  • sloc: cpp: 492,477; xml: 52,125; python: 13,519; ansic: 13,013; sh: 1,773; yacc: 853; makefile: 526; perl: 418; lex: 110; csh: 6
file content (41 lines) | stat: -rw-r--r-- 1,121 bytes parent folder | download
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
// Copyright (C) 2002 Brad King (brad.king@kitware.com) 
//                    Douglas Gregor (gregod@cs.rpi.edu)
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)

// For more information, see http://www.boost.org

#define BOOST_INCLUDE_MAIN
#include <boost/test/test_tools.hpp>
#include <boost/utility.hpp>

struct useless_type {};

class nonaddressable {
public:
  void dummy(); // Silence GCC warning: all member of class are private

private:
  useless_type operator&() const;
};

int test_main(int, char*[])
{
  nonaddressable* px = new nonaddressable();

  nonaddressable& x = *px;
  BOOST_TEST(boost::addressof(x) == px);

  const nonaddressable& cx = *px;
  BOOST_TEST(boost::addressof(cx) == static_cast<const nonaddressable*>(px));

  volatile nonaddressable& vx = *px;
  BOOST_TEST(boost::addressof(vx) == static_cast<volatile nonaddressable*>(px));

  const volatile nonaddressable& cvx = *px;
  BOOST_TEST(boost::addressof(cvx) == static_cast<const volatile nonaddressable*>(px));
  
  return 0;
}