Debian Codegraph @

clang/test/CXX/drs/cwg10xx.cpp

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