aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/cpp1z/constexpr-ref1.C
blob: 82771814a800ed111063079a5fb370980b52e0fb (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
// P2280R4 - Using unknown pointers and references in constant expressions
// PR c++/106650
// { dg-do compile { target c++17 } }

#include <type_traits>

template <typename T, typename U>
constexpr bool is_type(U &&)
{
    return std::is_same_v<T, std::decay_t<U>>;
}

auto visitor = [](auto&& v) {
    if constexpr(is_type<int>(v)) {
        // ...
    } else if constexpr(is_type<char>(v)) {
        // ...
    }
};

void
g (int i)
{
  visitor (i);
  constexpr bool b = is_type<int>(i);
}