C++ Logo

std-proposals

Advanced search

Shouldn't this context be unevaluated?

From: Omer Rosler <omer.rosler_at_[hidden]>
Date: Sat, 20 Mar 2021 19:41:06 +0200
When deducing a templated CNTTP inside a deduction guide, shouldn't the
context be unevaluated?

Consider the following snippet:

https://godbolt.org/z/5e4nTY

```c++
template<typename T>
constexpr T&& constexpr_declval() { return {};}

/************************************************/

template<auto V>
struct nttp_tag {};


/************************************************/
template<bool is_type>
struct use_ctad
{
    template<auto V> requires (!is_type)
    constexpr use_ctad(nttp_tag<V>) {}
};

template<auto V>
use_ctad(nttp_tag<V>) -> use_ctad<false>;

/**********************************************/
template<use_ctad t>
struct wrapper
{
    template<typename Tag>
    wrapper(Tag);
};

template<typename Tag>
wrapper(Tag) -> wrapper<use_ctad{constexpr_declval<Tag>()}>;

int main()
{
    wrapper t{nttp_tag<42>{}};
}
```

[Note: gcc complains about a deduction failure, which is probably a
compiler bug (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99683), clang
accepts this].

The deduction guide of `wrapper` uses a CTAD to deduce the NTTP, but in
this context there is no need to evaluate `constexpr_declval` (only perform
CTAD) as we only care about the deduction.

So my questions/proposals:

1. Should this context be unevaluated (unless I'm missing something, we
only deduce things and there is no need for evaluation), and we can remove
the definition (not declaration) of `constexpr_declval` and it would still
work?

2. If 1 is yes, shouldn't we make `std::declval` `constexpr` to support
this construct?

Received on 2021-03-20 12:41:23