view gcc/testsuite/g++.dg/cpp0x/constexpr-array-ptr6.C @ 145:1830386684a0

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

// { dg-do compile { target c++11 } }

typedef decltype(sizeof(char)) size_type;

template<class T, size_type N>
constexpr size_type size(T (&)[N]) { return N; }

double array_double[] = { 1.0, 2.0, 3.0 };

constexpr auto sz_d = size(array_double);

static_assert(sz_d == 3, "Array size failure");

void f(bool (&param)[2]) {
  static_assert(size(param) == 2, "Array size failure"); // { dg-error "" }
  short data[] = {-1, 2, -45, 6, 88, 99, -345};
  static_assert(size(data) == 7, "Array size failure");
}