This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 119e. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.

2026-04-17


3170. Failed consteval contracts while constructing a candidate set

Section: 6.11.2  [basic.contract.eval]     Status: NAD     Submitter: CWG     Date: 2026-03-25

Consider:

  template<class T>
  constexpr int v(T x)
    pre(x > 0)
  {
    return x;        // #1
    // return *T();  // #2
  }

  template<int> struct C;

  template<class T>
    constexpr int f(C<v(T())> *) { return 1; }  // #3
  template<class T>
    constexpr int f(void*) { return 2; }              // #4

  static_assert(f<int>((void*)0) == 2);

In general, certain instantiations are optional; see 13.9.2 [temp.inst] paragraph 9.

CWG 2026-03-27

The status quo specification is clear that the declaration (sans the defintion) of #3 is instantiated while constructing the candidate set, causing constant evaluation of v. Constant evaluation of a contract violation requires rejection of the program per 4.1.1 [intro.compliance.general] bullet 2.3.4.