brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.6 KiB · 6b54223 Raw
78 lines · cpp
1// RUN: %clang_cc1 -std=c++98 -triple x86_64-unknown-unknown %s -verify=expected,cxx98 -fexceptions -fcxx-exceptions -pedantic-errors -ast-dump | FileCheck %s --check-prefixes CXX982// RUN: %clang_cc1 -std=c++11 -triple x86_64-unknown-unknown %s -verify=expected,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors3// RUN: %clang_cc1 -std=c++14 -triple x86_64-unknown-unknown %s -verify=expected,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors4// RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-unknown %s -verify=expected,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors5// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-unknown %s -verify=expected,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors6// RUN: %clang_cc1 -std=c++23 -triple x86_64-unknown-unknown %s -verify=expected,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors7// RUN: %clang_cc1 -std=c++2c -triple x86_64-unknown-unknown %s -verify=expected,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors8 9#if __cplusplus == 199711L10#define static_assert(...) __extension__ _Static_assert(__VA_ARGS__)11// cxx98-error@-1 {{variadic macros are a C99 feature}}12#endif13 14namespace cwg2149 { // cwg2149: 3.115#if __cplusplus <= 201103L16struct X { int i, j, k; };17#else18struct X { int i, j, k = 42; };19#endif20 21template<int N>22void f1(const X(&)[N]); // #cwg2149-f123 24template<int N>25void f2(const X(&)[N][2]); // #cwg2149-f226 27void f() {28  X a[] = { 1, 2, 3, 4, 5, 6 };29  static_assert(sizeof(a) / sizeof(X) == 2, "");30  X b[2] = { { 1, 2, 3 }, { 4, 5, 6 } };31  X c[][2] = { 1, 2, 3, 4, 5, 6 };32  static_assert(sizeof(c) / sizeof(X[2]) == 1, "");33 34  #if __cplusplus >= 201103L35  constexpr X ca[] = { 1, 2, 3, 4, 5, 6 };36  constexpr X cb[2] = { { 1, 2, 3 }, { 4, 5, 6 } };37  static_assert(ca[0].i == cb[0].i, "");38  static_assert(ca[0].j == cb[0].j, "");39  static_assert(ca[0].k == cb[0].k, "");40  static_assert(ca[1].i == cb[1].i, "");41  static_assert(ca[1].j == cb[1].j, "");42  static_assert(ca[1].k == cb[1].k, "");43 44  f1({ 1, 2, 3, 4, 5, 6 });45  // since-cxx11-error@-1 {{no matching function for call to 'f1'}}46  //   since-cxx11-note@#cwg2149-f1 {{candidate function [with N = 6] not viable: no known conversion from 'int' to 'const X' for 1st argument}}47  f2({ 1, 2, 3, 4, 5, 6 });48  // since-cxx11-error@-1 {{no matching function for call to 'f2'}}49  //   since-cxx11-note@#cwg2149-f2 {{candidate function [with N = 6] not viable: no known conversion from 'int' to 'const X[2]' for 1st argument}}50  #endif51}52} // namespace cwg214953 54// Constant evaluation is not powerful enough in 98 mode to check for equality55// via static_assert, even with constant folding enabled.56 57// CXX98:       VarDecl {{.+}} a 'X[2]'58// CXX98-NEXT:  `-InitListExpr {{.+}} 'X[2]'59// CXX98-NEXT:    |-InitListExpr {{.+}} 'X'{{$}}60// CXX98-NEXT:    | |-IntegerLiteral {{.+}} 'int' 161// CXX98-NEXT:    | |-IntegerLiteral {{.+}} 'int' 262// CXX98-NEXT:    | `-IntegerLiteral {{.+}} 'int' 363// CXX98-NEXT:    `-InitListExpr {{.+}} 'X'{{$}}64// CXX98-NEXT:      |-IntegerLiteral {{.+}} 'int' 465// CXX98-NEXT:      |-IntegerLiteral {{.+}} 'int' 566// CXX98-NEXT:      `-IntegerLiteral {{.+}} 'int' 667 68// CXX98:       VarDecl {{.+}} b 'X[2]'69// CXX98-NEXT:  `-InitListExpr {{.+}} 'X[2]'70// CXX98-NEXT:    |-InitListExpr {{.+}} 'X'{{$}}71// CXX98-NEXT:    | |-IntegerLiteral {{.+}} 'int' 172// CXX98-NEXT:    | |-IntegerLiteral {{.+}} 'int' 273// CXX98-NEXT:    | `-IntegerLiteral {{.+}} 'int' 374// CXX98-NEXT:    `-InitListExpr {{.+}} 'X'{{$}}75// CXX98-NEXT:      |-IntegerLiteral {{.+}} 'int' 476// CXX98-NEXT:      |-IntegerLiteral {{.+}} 'int' 577// CXX98-NEXT:      `-IntegerLiteral {{.+}} 'int' 678