| 1 |
// RUN: %clang_cc1 -std=c++98 %s -verify=expected -fexceptions -fcxx-exceptions -pedantic-errors |
| 2 |
// RUN: %clang_cc1 -std=c++11 %s -verify=expected -fexceptions -fcxx-exceptions -pedantic-errors |
| 3 |
// RUN: %clang_cc1 -std=c++14 %s -verify=expected,since-cxx14 -fexceptions -fcxx-exceptions -pedantic-errors |
| 4 |
// RUN: %clang_cc1 -std=c++17 %s -verify=expected,since-cxx14 -fexceptions -fcxx-exceptions -pedantic-errors |
| 5 |
// RUN: %clang_cc1 -std=c++20 %s -verify=expected,since-cxx14 -fexceptions -fcxx-exceptions -pedantic-errors |
| 6 |
// RUN: %clang_cc1 -std=c++23 %s -verify=expected,since-cxx14 -fexceptions -fcxx-exceptions -pedantic-errors |
| 7 |
// RUN: %clang_cc1 -std=c++2c %s -verify=expected,since-cxx14 -fexceptions -fcxx-exceptions -pedantic-errors |
| 8 |
|
| 9 |
namespace std { |
| 10 |
__extension__ typedef __SIZE_TYPE__ size_t; |
| 11 |
|
| 12 |
template<typename T> struct initializer_list { |
| 13 |
const T *p; size_t n; |
| 14 |
initializer_list(const T *p, size_t n); |
| 15 |
}; |
| 16 |
} // namespace std |
| 17 |
|
| 18 |
namespace cwg1004 { // cwg1004: 5 |
| 19 |
template<typename> struct A {}; |
| 20 |
template<typename> struct B1 {}; |
| 21 |
template<template<typename> class> struct B2 {}; |
| 22 |
template<typename X> void f(); // #cwg1004-f-1 |
| 23 |
template<template<typename> class X> void f(); // #cwg1004-f-2 |
| 24 |
template<template<typename> class X> void g(); // #cwg1004-g-1 |
| 25 |
template<typename X> void g(); // #cwg1004-g-2 |
| 26 |
struct C : A<int> { |
| 27 |
B1<A> b1a; |
| 28 |
B2<A> b2a; |
| 29 |
void h() { |
| 30 |
f<A>(); |
| 31 |
// expected-error@-1 {{call to 'f' is ambiguous}} |
| 32 |
// expected-note@#cwg1004-f-1 {{candidate function [with X = cwg1004::A<int>]}} |
| 33 |
// expected-note@#cwg1004-f-2 {{candidate function [with X = cwg1004::A]}} |
| 34 |
g<A>(); |
| 35 |
// expected-error@-1 {{call to 'g' is ambiguous}} |
| 36 |
// expected-note@#cwg1004-g-1 {{candidate function [with X = cwg1004::A]}} |
| 37 |
// expected-note@#cwg1004-g-2 {{candidate function [with X = cwg1004::A<int>]}} |
| 38 |
} |
| 39 |
}; |
| 40 |
|
| 41 |
// This example (from the standard) is actually ill-formed, because |
| 42 |
// name lookup of "T::template A" names the constructor. |
| 43 |
template<class T, template<class> class U = T::template A> struct Third { }; |
| 44 |
// expected-error@-1 {{is a constructor name}} |
| 45 |
// expected-note@#cwg1004-t {{in instantiation of default argument}} |
| 46 |
Third<A<int> > t; // #cwg1004-t |
| 47 |
} // namespace cwg1004 |
| 48 |
|
| 49 |
namespace cwg1042 { // cwg1042: 3.5 |
| 50 |
#if __cplusplus >= 201402L |
| 51 |
// C++14 added an attribute that we can test the semantics of. |
| 52 |
using foo [[deprecated]] = int; // #cwg1042-using |
| 53 |
foo f = 12; |
| 54 |
// since-cxx14-warning@-1 {{'foo' is deprecated}} |
| 55 |
// since-cxx14-note@#cwg1042-using {{'foo' has been explicitly marked deprecated here}} |
| 56 |
#elif __cplusplus >= 201103L |
| 57 |
// C++11 did not have any attributes that could be applied to an alias |
| 58 |
// declaration, so the best we can test is that we accept an empty attribute |
| 59 |
// list in this mode. |
| 60 |
using foo [[]] = int; |
| 61 |
#endif |
| 62 |
} // namespace cwg1042 |
| 63 |
|
| 64 |
namespace cwg1048 { // cwg1048: 3.6 |
| 65 |
struct A {}; |
| 66 |
const A f(); |
| 67 |
A g(); |
| 68 |
typedef const A CA; |
| 69 |
#if __cplusplus >= 201103L |
| 70 |
// ok: we deduce non-const A in each case. |
| 71 |
A &&a = [] (int n) { |
| 72 |
while (1) switch (n) { |
| 73 |
case 0: return f(); |
| 74 |
case 1: return g(); |
| 75 |
case 2: return A(); |
| 76 |
case 3: return CA(); |
| 77 |
} |
| 78 |
} (0); |
| 79 |
#endif |
| 80 |
} // namespace cwg1048 |
| 81 |
|
| 82 |
namespace cwg1054 { // cwg1054: no |
| 83 |
// FIXME: Test is incomplete. |
| 84 |
struct A {} volatile a; |
| 85 |
void f() { |
| 86 |
// FIXME: This is wrong: an lvalue-to-rvalue conversion is applied here, |
| 87 |
// which copy-initializes a temporary from 'a'. Therefore this is |
| 88 |
// ill-formed because A does not have a volatile copy constructor. |
| 89 |
// (We might want to track this aspect under cwg1383 instead?) |
| 90 |
a; |
| 91 |
// expected-warning@-1 {{expression result unused; assign into a variable to force a volatile load}} |
| 92 |
} |
| 93 |
} // namespace cwg1054 |
| 94 |
|
| 95 |
namespace cwg1070 { // cwg1070: 3.5 |
| 96 |
#if __cplusplus >= 201103L |
| 97 |
struct A { |
| 98 |
A(std::initializer_list<int>); |
| 99 |
}; |
| 100 |
struct B { |
| 101 |
int i; |
| 102 |
A a; |
| 103 |
}; |
| 104 |
B b = {1}; |
| 105 |
struct C { |
| 106 |
std::initializer_list<int> a; |
| 107 |
B b; |
| 108 |
std::initializer_list<double> c; |
| 109 |
}; |
| 110 |
C c = {}; |
| 111 |
#endif |
| 112 |
} // namespace cwg1070 |