brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.0 KiB · dde8a9e Raw
55 lines · cpp
1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9// <memory>10 11// template <ObjectType T> T* addressof(T& r);12 13#include <memory>14#include <cassert>15 16#include "test_macros.h"17 18struct A19{20    void operator&() const {}21};22 23struct nothing {24    operator char&()25    {26        static char c;27        return c;28    }29};30 31int main(int, char**)32{33    {34    int i;35    double d;36    assert(std::addressof(i) == &i);37    assert(std::addressof(d) == &d);38    A* tp = new A;39    const A* ctp = tp;40    assert(std::addressof(*tp) == tp);41    assert(std::addressof(*ctp) == tp);42    delete tp;43    }44    {45    union46    {47        nothing n;48        int i;49    };50    assert(std::addressof(n) == (void*)std::addressof(i));51    }52 53  return 0;54}55