]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/20_util/addressof/requirements/constexpr.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 20_util / addressof / requirements / constexpr.cc
CommitLineData
a945c346 1// Copyright (C) 2016-2024 Free Software Foundation, Inc.
9e023e33
JW
2//
3// This file is part of the GNU ISO C++ Library. This library is free
4// software; you can redistribute it and/or modify it under the
5// terms of the GNU General Public License as published by the
6// Free Software Foundation; either version 3, or (at your option)
7// any later version.
8
9// This library is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13
14// You should have received a copy of the GNU General Public License along
15// with this library; see the file COPYING3. If not see
16// <http://www.gnu.org/licenses/>.
17
7b936140 18// { dg-do compile { target c++17 } }
f4ab6846 19// { dg-add-options no_pch }
9e023e33
JW
20
21#include <utility>
22
23// LWG 2296 std::addressof should be constexpr
24
25#ifndef __cpp_lib_addressof_constexpr
26# error "Feature-test macro for constexpr addressof missing"
27#elif __cpp_lib_addressof_constexpr != 201603
28# error "Feature-test macro for constexpr addressof has wrong value"
29#endif
30
31int i;
32constexpr int* pi = std::addressof(i);
33static_assert( pi == &i, "&i" );
34
35struct X {
36 void operator&();
37 constexpr X* addr() { return this; }
38 constexpr const X* addr() const { return this; }
39};
40X x;
41constexpr X* px = std::addressof(x);
42static_assert( px == x.addr(), "x.addr()" );
43const X cx;
44constexpr const X* pcx = std::addressof(cx);
45static_assert( pcx == cx.addr(), "cx.addr()" );
46
47void
48test01()
49{
50 static int i2;
51 static_assert( std::addressof(i2) == &i2, "&i2" );
52
53 static X x2;
54 static_assert( std::addressof(x2) == x2.addr(), "x2.addr()" );
55}