view gcc/testsuite/g++.dg/cpp2a/array-conv8.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

// PR c++/69531 - DR 1307, Overload resolution based on size of array init-list.
// { dg-do run { target c++2a } }
// Example from [over.ics.rank].

int f(int    (&&)[] ) { return 1; }    // #1
int f(double (&&)[] ) { return 2; }    // #2
int f(int    (&&)[2]) { return 3; }    // #3

int
main ()
{
  // Calls #1: Better than #2 due to conversion, better than #3 due to bounds.
  if (f({1}) != 1)
     __builtin_abort ();
  // Calls #2: Identity conversion is better than floating-integral conversion.
  if (f({1.0}) != 2)
     __builtin_abort ();
  // Calls #2: Identity conversion is better than floating-integral conversion.
  if (f({1.0, 2.0}) != 2)
     __builtin_abort ();
  // Calls #3: Converting to array of known bound is better than to unknown
  // bound, and an identity conversion is better than floating-integral
  // conversion.
  if (f({1, 2}) != 3)
     __builtin_abort ();
}