1 // RUN: %clang_cc1 -std=c++1z -verify %s
2 // RUN: %clang_cc1 -std=c++1z -verify %s -DUNDEFINED
5 // "used but not defined" errors don't get produced if we have more interesting
7 namespace std_example
{
8 template <typename T
, typename
... Rest
> void g(T
&&p
, Rest
&&... rs
) {
10 if constexpr(sizeof...(rs
) > 0)
17 static int x(); // no definition of x required
28 namespace odr_use_in_selected_arm
{
29 static int x(); // expected-warning {{is not defined}}
33 else if (x()) // expected-note {{here}}
49 template<int N
> void g() {
55 if constexpr (4.3) { //expected-warning {{implicit conversion from 'double' to 'bool' changes value}}
57 constexpr void *p
= nullptr;
62 void not_constant(int b
, S s
) { // expected-note 2{{declared here}}
63 if constexpr (bool(b
)) { // expected-error {{constexpr if condition is not a constant expression}} expected-note {{cannot be used in a constant expression}}
65 if constexpr (b
) { // expected-error {{constexpr if condition is not a constant expression}} expected-note {{cannot be used in a constant expression}}
67 if constexpr (s
) { // expected-error {{value of type 'S' is not contextually convertible to 'bool'}}
70 constexpr S constexprS
;
71 if constexpr (constexprS
) { // expected-error {{value of type 'const S' is not contextually convertible to 'bool'}}
76 namespace generic_lambda
{
77 // Substituting for T produces a hard error here, even if substituting for
78 // the type of x would remove the error.
79 template<typename T
> void f() {
81 if constexpr (sizeof(T
) == 1 && sizeof(x
) == 1)
82 T::error(); // expected-error 2{{'::'}}
83 // expected-note@-3 2{{while substituting into a lambda expression here}}
87 template<typename T
> void g() {
89 if constexpr (sizeof(T
) == 1)
90 if constexpr (sizeof(x
) == 1)
91 T::error(); // expected-error {{'::'}}
92 // expected-note@-4 {{while substituting into a lambda expression here}}
97 f
<int>(); // expected-note {{instantiation of}}
98 f
<char>(); // expected-note {{instantiation of}}
100 g
<char>(); // expected-note {{instantiation of}}
104 namespace potentially_discarded_branch_target
{
105 void in_switch(int n
) {
107 case 4: if constexpr(sizeof(n
) == 4) return;
108 if constexpr(sizeof(n
) == 4)
109 switch (n
) case 4: return;
111 if constexpr (sizeof(n
) == 4) // expected-note 2{{constexpr if}}
112 case 4: return; // expected-error {{cannot jump}}
114 default: break; // expected-error {{cannot jump}}
119 void in_switch_tmpl(int n
) {
121 if constexpr (sizeof(T
) == 4) // expected-note 2{{constexpr if}}
122 case 4: return; // expected-error {{cannot jump}}
124 default: break; // expected-error {{cannot jump}}
128 void goto_scope(int n
) {
129 goto foo
; // expected-error {{cannot jump}}
130 if constexpr(sizeof(n
) == 4) // expected-note {{constexpr if}}
133 if constexpr(sizeof(n
) == 4)
138 void goto_scope(int n
) {
139 goto foo
; // expected-error {{cannot jump}}
140 if constexpr(sizeof(n
) == 4) // expected-note {{constexpr if}}
143 if constexpr(sizeof(n
) == 4)
147 void goto_redef(int n
) {
148 a
: if constexpr(sizeof(n
) == 4) // expected-error {{redefinition}} expected-note {{constexpr if}}
149 a
: goto a
; // expected-note 2{{previous}}
151 a
: goto a
; // expected-error {{redefinition}} expected-error {{cannot jump}}
155 goto evil_label
; // expected-error {{cannot jump}}
156 if constexpr (true || ({evil_label
: false;})) {} // expected-note {{constexpr if}} \
157 // expected-note {{jump enters a statement expression}}
159 if constexpr (true) // expected-note {{constexpr if}}
160 goto surprise
; // expected-error {{cannot jump}}
166 namespace deduced_return_type_in_discareded_statement
{
168 template <typename T
>
174 if constexpr (false) {
178 } // namespace deduced_return_type_in_discareded_statement