[flang][cuda] Adapt ExternalNameConversion to work in gpu module (#117039)
[llvm-project.git] / clang / test / AST / ByteCode / cxx2a.cpp
blobeaae978e011843e3ca624d404872247a48ef7be6
1 // RUN: %clang_cc1 -std=c++2a -fsyntax-only -fcxx-exceptions -verify=ref,both %s
2 // RUN: %clang_cc1 -std=c++2a -fsyntax-only -fcxx-exceptions -verify=expected,both %s -fexperimental-new-constant-interpreter
4 template <unsigned N>
5 struct S {
6 S() requires (N==1) = default;
7 S() requires (N==2) {} // both-note {{declared here}}
8 consteval S() requires (N==3) = default;
9 };
11 consteval int aConstevalFunction() { // both-error {{consteval function never produces a constant expression}}
12 S<2> s4; // both-note {{non-constexpr constructor 'S' cannot be used in a constant expression}}
13 return 0;
15 /// We're NOT calling the above function. The diagnostics should appear anyway.
17 namespace Covariant {
18 struct A {
19 virtual constexpr char f() const { return 'Z'; }
20 char a = f();
23 struct D : A {};
24 struct Covariant1 {
25 D d;
26 virtual const A *f() const;
29 struct Covariant3 : Covariant1 {
30 constexpr virtual const D *f() const { return &this->d; }
33 constexpr Covariant3 cb;
34 constexpr const Covariant1 *cb1 = &cb;
35 static_assert(cb1->f()->a == 'Z');
38 namespace DtorOrder {
39 struct Buf {
40 char buf[64];
41 int n = 0;
42 constexpr void operator+=(char c) { buf[n++] = c; }
43 constexpr bool operator==(const char *str) const {
44 if (str[n] != 0)
45 return false;
47 for (int i = 0; i < n; ++i) {
48 if (buf[n] != str[n])
49 return false;
51 return true;
53 return __builtin_memcmp(str, buf, n) == 0;
55 constexpr bool operator!=(const char *str) const { return !operator==(str); }
58 struct A {
59 constexpr A(Buf &buf, char c) : buf(buf), c(c) { buf += c; }
60 constexpr ~A() { buf += (c - 32);}
61 constexpr operator bool() const { return true; }
62 Buf &buf;
63 char c;
66 constexpr void abnormal_termination(Buf &buf) {
67 struct Indestructible {
68 constexpr ~Indestructible(); // not defined
70 A a(buf, 'a');
71 A(buf, 'b');
72 int n = 0;
74 for (A &&c = A(buf, 'c'); A d = A(buf, 'd'); A(buf, 'e')) {
75 switch (A f(buf, 'f'); A g = A(buf, 'g')) { // both-warning {{boolean}}
76 case false: {
77 A x(buf, 'x');
80 case true: {
81 A h(buf, 'h');
82 switch (n++) {
83 case 0:
84 break;
85 case 1:
86 continue;
87 case 2:
88 return;
90 break;
93 default:
94 Indestructible indest;
97 A j = (A(buf, 'i'), A(buf, 'j'));
101 constexpr bool check_abnormal_termination() {
102 Buf buf = {};
103 abnormal_termination(buf);
104 return buf ==
105 "abBc"
106 "dfgh" /*break*/ "HGFijIJeED"
107 "dfgh" /*continue*/ "HGFeED"
108 "dfgh" /*return*/ "HGFD"
109 "CA";
111 static_assert(check_abnormal_termination());