brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.0 KiB · 94d9941 Raw
79 lines · cpp
1// RUN: %clang_cc1 -fsyntax-only -verify %s 2// RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s3// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s4 5struct ConvToBool {6  operator bool() const;7};8 9struct ConvToInt {10  operator int();11};12 13struct ExplicitConvToBool {14  explicit operator bool(); // expected-note {{explicit}}15#if __cplusplus <= 199711L // C++03 or earlier modes16  // expected-warning@-2{{explicit conversion functions are a C++11 extension}}17#endif18};19 20void test_conv_to_bool(ConvToBool ctb, ConvToInt cti, ExplicitConvToBool ecb) {21  if (ctb) { }22  if (cti) { }23  if (ecb) { }24  for (; ctb; ) { }25  for (; cti; ) { }26  for (; ecb; ) { }27  while (ctb) { };28  while (cti) { }29  while (ecb) { }30  do { } while (ctb);31  do { } while (cti);32  do { } while (ecb);33 34  if (!ctb) { }35  if (!cti) { }36  if (!ecb) { }37 38  bool b1 = !ecb;39  if (ctb && ecb) { }40  bool b2 = ctb && ecb;41  if (ctb || ecb) { }42  bool b3 = ctb || ecb;43}44 45void accepts_bool(bool) { } // expected-note{{candidate function}}46 47struct ExplicitConvToRef {48  explicit operator int&(); // expected-note {{explicit}}49#if (__cplusplus <= 199711L) // C++03 or earlier modes50  // expected-warning@-2{{explicit conversion functions are a C++11 extension}}51#endif52};53 54void test_explicit_bool(ExplicitConvToBool ecb) {55  bool b1(ecb); // okay56  bool b2 = ecb; // expected-error{{no viable conversion from 'ExplicitConvToBool' to 'bool'}}57  accepts_bool(ecb); // expected-error{{no matching function for call to}}58}59 60void test_explicit_conv_to_ref(ExplicitConvToRef ecr) {61  int& i1 = ecr; // expected-error{{no viable conversion from 'ExplicitConvToRef' to 'int'}}62  int& i2(ecr); // okay63}64 65struct A { };66struct B { };67struct C {68  explicit operator A&();  // expected-note {{explicit}}69#if __cplusplus <= 199711L // C++03 or earlier modes70// expected-warning@-2{{explicit conversion functions are a C++11 extension}}71#endif72  operator B&(); // expected-note{{candidate}}73};74 75void test_copy_init_conversions(C c) {76  A &a = c; // expected-error{{no viable conversion from 'C' to 'A'}}77  B &b = c; // okay78}79