File: cwg2149.cpp

package info (click to toggle)
llvm-toolchain-21 1%3A21.1.6-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,245,028 kB
  • sloc: cpp: 7,619,726; ansic: 1,434,018; asm: 1,058,748; python: 252,740; f90: 94,671; objc: 70,685; lisp: 42,813; pascal: 18,401; sh: 8,601; ml: 5,111; perl: 4,720; makefile: 3,675; awk: 3,523; javascript: 2,409; xml: 892; fortran: 770
file content (77 lines) | stat: -rw-r--r-- 3,707 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// 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 CXX98
// RUN: %clang_cc1 -std=c++11 -triple x86_64-unknown-unknown %s -verify=expected,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors
// RUN: %clang_cc1 -std=c++14 -triple x86_64-unknown-unknown %s -verify=expected,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors
// RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-unknown %s -verify=expected,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors
// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-unknown %s -verify=expected,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors
// RUN: %clang_cc1 -std=c++23 -triple x86_64-unknown-unknown %s -verify=expected,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors
// RUN: %clang_cc1 -std=c++2c -triple x86_64-unknown-unknown %s -verify=expected,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors

#if __cplusplus == 199711L
#define static_assert(...) __extension__ _Static_assert(__VA_ARGS__)
// cxx98-error@-1 {{variadic macros are a C99 feature}}
#endif

namespace cwg2149 { // cwg2149: 3.1
#if __cplusplus <= 201103L
struct X { int i, j, k; };
#else
struct X { int i, j, k = 42; };
#endif

template<int N>
void f1(const X(&)[N]); // #cwg2149-f1

template<int N>
void f2(const X(&)[N][2]); // #cwg2149-f2

void f() {
  X a[] = { 1, 2, 3, 4, 5, 6 };
  static_assert(sizeof(a) / sizeof(X) == 2, "");
  X b[2] = { { 1, 2, 3 }, { 4, 5, 6 } };
  X c[][2] = { 1, 2, 3, 4, 5, 6 };
  static_assert(sizeof(c) / sizeof(X[2]) == 1, "");

  #if __cplusplus >= 201103L
  constexpr X ca[] = { 1, 2, 3, 4, 5, 6 };
  constexpr X cb[2] = { { 1, 2, 3 }, { 4, 5, 6 } };
  static_assert(ca[0].i == cb[0].i, "");
  static_assert(ca[0].j == cb[0].j, "");
  static_assert(ca[0].k == cb[0].k, "");
  static_assert(ca[1].i == cb[1].i, "");
  static_assert(ca[1].j == cb[1].j, "");
  static_assert(ca[1].k == cb[1].k, "");

  f1({ 1, 2, 3, 4, 5, 6 });
  // since-cxx11-error@-1 {{no matching function for call to 'f1'}}
  //   since-cxx11-note@#cwg2149-f1 {{candidate function [with N = 6] not viable: no known conversion from 'int' to 'const X' for 1st argument}}
  f2({ 1, 2, 3, 4, 5, 6 });
  // since-cxx11-error@-1 {{no matching function for call to 'f2'}}
  //   since-cxx11-note@#cwg2149-f2 {{candidate function [with N = 6] not viable: no known conversion from 'int' to 'const X[2]' for 1st argument}}
  #endif
}
} // namespace cwg2149

// Constant evaluation is not powerful enough in 98 mode to check for equality
// via static_assert, even with constant folding enabled.

// CXX98:       VarDecl {{.+}} a 'X[2]'
// CXX98-NEXT:  `-InitListExpr {{.+}} 'X[2]'
// CXX98-NEXT:    |-InitListExpr {{.+}} 'X':'cwg2149::X'
// CXX98-NEXT:    | |-IntegerLiteral {{.+}} 'int' 1
// CXX98-NEXT:    | |-IntegerLiteral {{.+}} 'int' 2
// CXX98-NEXT:    | `-IntegerLiteral {{.+}} 'int' 3
// CXX98-NEXT:    `-InitListExpr {{.+}} 'X':'cwg2149::X'
// CXX98-NEXT:      |-IntegerLiteral {{.+}} 'int' 4
// CXX98-NEXT:      |-IntegerLiteral {{.+}} 'int' 5
// CXX98-NEXT:      `-IntegerLiteral {{.+}} 'int' 6

// CXX98:       VarDecl {{.+}} b 'X[2]'
// CXX98-NEXT:  `-InitListExpr {{.+}} 'X[2]'
// CXX98-NEXT:    |-InitListExpr {{.+}} 'X':'cwg2149::X'
// CXX98-NEXT:    | |-IntegerLiteral {{.+}} 'int' 1
// CXX98-NEXT:    | |-IntegerLiteral {{.+}} 'int' 2
// CXX98-NEXT:    | `-IntegerLiteral {{.+}} 'int' 3
// CXX98-NEXT:    `-InitListExpr {{.+}} 'X':'cwg2149::X'
// CXX98-NEXT:      |-IntegerLiteral {{.+}} 'int' 4
// CXX98-NEXT:      |-IntegerLiteral {{.+}} 'int' 5
// CXX98-NEXT:      `-IntegerLiteral {{.+}} 'int' 6