~ubuntu-branches/ubuntu/saucy/dune-common/saucy-proposed

« back to all changes in this revision

Viewing changes to dune/common/test/nullptr-test.cc

  • Committer: Package Import Robot
  • Author(s): Ansgar Burchardt
  • Date: 2012-03-17 17:15:13 UTC
  • Revision ID: package-import@ubuntu.com-20120317171513-l2eqm95mddmu2dj3
Tags: upstream-2.2~svn6573
ImportĀ upstreamĀ versionĀ 2.2~svn6573

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifdef HAVE_CONFIG_H
 
2
#include "config.h"
 
3
#endif
 
4
 
 
5
#include <dune/common/nullptr.hh>
 
6
 
 
7
void basic_tests()
 
8
{
 
9
    typedef Dune::nullptr_t NULLPTR_T;
 
10
    char* ch = nullptr;  // ch has the null pointer value
 
11
    char* ch2 = 0;       // ch2 has the null pointer value
 
12
#ifdef FAIL
 
13
    int n = nullptr;     // error
 
14
    ++n;
 
15
#endif
 
16
    int n2 = 0;          // n2 is zero
 
17
    if( ch == 0 );       // evaluates to true
 
18
    if( ch == nullptr ); // evaluates to true
 
19
    if( nullptr == ch ); // evaluates to true
 
20
    if( ch );            // evaluates to false
 
21
    if( n2 == 0 );       // evaluates to true
 
22
    ch = ch2;
 
23
#ifdef FAIL
 
24
    if( n2 == nullptr ); // error
 
25
    if( nullptr );       // error, no conversion to bool
 
26
    if( nullptr == 0 );  // error
 
27
    // arithmetic
 
28
    nullptr = 0;         // error, nullptr is not an lvalue
 
29
    nullptr + 2;         // error
 
30
#endif
 
31
}
 
32
 
 
33
int main()
 
34
{
 
35
    basic_tests();
 
36
    return 0;
 
37
}