view gcc/testsuite/g++.dg/cpp2a/consteval4.C @ 145:1830386684a0

gcc-9.2.0
author anatofuz
date Thu, 13 Feb 2020 11:34:05 +0900
parents
children
line wrap: on
line source

// { dg-do run }
// { dg-options "-std=c++2a" }

extern "C" void abort ();
namespace std {
  constexpr inline bool
  is_constant_evaluated () noexcept
  {
    return __builtin_is_constant_evaluated ();
  }
}

int
main ()
{
  constexpr int a = 5;
  auto b = [] (int n) consteval { return n + a + std::is_constant_evaluated (); };
  int c = b (4);
  if (c != 10)
    abort ();
  auto d = [] () consteval { return a + std::is_constant_evaluated (); };
  int e = d ();
  if (e != 6)
    abort ();
  constexpr int f = d ();
  if (f != 6)
    abort ();
  static_assert (d () == 6);
}