1 // RUN: %clang_cc1 -std=c++20 -fsyntax-only %s -verify
3 #define UIE __attribute__((using_if_exists))
8 using NS::x UIE
; // expected-note{{using declaration annotated with 'using_if_exists' here}}
9 x
usex(); // expected-error{{reference to unresolved using declaration}}
11 using NotNS::x UIE
; // expected-error{{use of undeclared identifier 'NotNS'}}
13 using NS::NotNS::x UIE
; // expected-error{{no member named 'NotNS' in namespace 'test_basic::NS'}}
14 } // namespace test_basic
16 namespace test_redecl
{
25 int A(); // expected-note{{target of using declaration}}
26 struct B
{}; // expected-note{{target of using declaration}}
27 int C(); // expected-note{{conflicting declaration}}
28 struct D
{}; // expected-note{{conflicting declaration}}
32 using NS2::A UIE
; // expected-note{{using declaration annotated with 'using_if_exists' here}} expected-note{{conflicting declaration}}
33 using NS3::A UIE
; // expected-error{{target of using declaration conflicts with declaration already in scope}}
34 int i
= A(); // expected-error{{reference to unresolved using declaration}}
37 using NS2::B UIE
; // expected-note{{conflicting declaration}} expected-note{{using declaration annotated with 'using_if_exists' here}}
38 using NS3::B UIE
; // expected-error{{target of using declaration conflicts with declaration already in scope}}
39 B myB
; // expected-error{{reference to unresolved using declaration}}
42 using NS2::C UIE
; // expected-error{{target of using declaration conflicts with declaration already in scope}} expected-note{{target of using declaration}}
46 using NS2::D UIE
; // expected-error{{target of using declaration conflicts with declaration already in scope}} expected-note{{target of using declaration}}
48 } // namespace test_redecl
50 namespace test_dependent
{
53 using B::mf UIE
; // expected-note 3 {{using declaration annotated with 'using_if_exists' here}}
54 using typename
B::mt UIE
; // expected-note{{using declaration annotated with 'using_if_exists' here}}
65 struct UseCtor
: Base
{
66 using Base::Base UIE
; // expected-error{{'using_if_exists' attribute cannot be applied to an inheriting constructor}}
72 S
<BaseNonEmpty
> nonempty
;
73 empty
.mf(); // expected-error {{reference to unresolved using declaration}}
75 (&empty
)->mf(); // expected-error {{reference to unresolved using declaration}}
78 S
<BaseEmpty
>::mt y
; // expected-error {{reference to unresolved using declaration}}
79 S
<BaseNonEmpty
>::mt z
;
81 S
<BaseEmpty
>::mf(); // expected-error {{reference to unresolved using declaration}}
83 UseCtor
<BaseCtor
> usector
;
88 using B::mf UIE
; // expected-note {{using declaration annotated with 'using_if_exists' here}}
89 using typename
B::mt UIE
; // expected-note 2 {{using declaration annotated with 'using_if_exists' here}}
92 mf(); // expected-error {{reference to unresolved using declaration}}
93 mt x
; // expected-error {{reference to unresolved using declaration}}
96 mt
alsoUse(); // expected-error {{reference to unresolved using declaration}}
100 Implicit
<BaseNonEmpty
> nonempty
;
101 Implicit
<BaseEmpty
> empty
; // expected-note {{in instantiation}}
103 empty
.use(); // expected-note {{in instantiation}}
107 struct NonDep
: BaseEmpty
{
108 using BaseEmpty::x UIE
; // expected-note{{using declaration annotated with 'using_if_exists' here}}
109 x
y(); // expected-error{{reference to unresolved using declaration}}
111 } // namespace test_dependent
113 namespace test_using_pack
{
114 template <class... Ts
>
116 using typename
Ts::x
... UIE
; // expected-error 2 {{target of using declaration conflicts with declaration already in scope}} expected-note{{conflicting declaration}} expected-note{{target of using declaration}}
124 typedef int x
; // expected-note 2 {{conflicting declaration}}
127 typedef int x
; // expected-note 2 {{target of using declaration}}
131 S
<E1
, F2
> c
; // expected-note{{in instantiation of template class}}
132 S
<F1
, E2
> d
; // expected-note{{in instantiation of template class}}
134 template <class... Ts
>
136 using typename
Ts::x
... UIE
; // expected-error 2 {{target of using declaration conflicts with declaration already in scope}} expected-note 3 {{using declaration annotated with 'using_if_exists' here}} expected-note{{conflicting declaration}} expected-note{{target of using declaration}}
138 x
mem(); // expected-error 3 {{reference to unresolved using declaration}}
141 S2
<E1
, E2
> e
; // expected-note{{in instantiation of template class}}
143 S2
<E1
, F2
> g
; // expected-note{{in instantiation of template class}}
144 S2
<F1
, E2
> h
; // expected-note{{in instantiation of template class}}
146 template <class... Ts
>
147 struct S3
: protected Ts
... {
148 using Ts::m
... UIE
; // expected-error{{target of using declaration conflicts with declaration already in scope}} expected-note{{target of using declaration}}
151 enum { m
}; // expected-note{{conflicting declaration}}
155 S3
<B1
, B2
> i
; // expected-note{{in instantiation of template}}
158 } // namespace test_using_pack
160 namespace test_nested
{
163 using NS::x UIE
; // expected-note {{using declaration annotated with 'using_if_exists' here}}
166 using ::test_nested::x UIE
;
169 NS2::x y
; // expected-error {{reference to unresolved using declaration}}
170 } // namespace test_nested
172 namespace test_scope
{
173 int x
; // expected-note{{conflicting declaration}}
175 int x
; // expected-note{{conflicting declaration}}
177 using ::x UIE
; // expected-note {{using declaration annotated with 'using_if_exists' here}}
178 (void)x
; // expected-error {{reference to unresolved using declaration}}
183 using ::x UIE
; // expected-error{{target of using declaration conflicts with declaration already in scope}} expected-note{{target of using declaration}}
189 using ::x UIE
; // expected-error{{target of using declaration conflicts with declaration already in scope}} expected-note{{target of using declaration}}
192 } // namespace test_scope
194 namespace test_appertains_to
{
199 // FIXME: This diagnostics is wrong.
200 using alias UIE
= NS::x
; // expected-error {{'using_if_exists' attribute only applies to named declarations, types, and value declarations}}
203 using template_alias UIE
= NS::x
; // expected-error {{'using_if_exists' attribute only applies to named declarations, types, and value declarations}}
205 void f() UIE
; // expected-error {{'using_if_exists' attribute only applies to named declarations, types, and value declarations}}
207 using namespace NS UIE
; // expected-error {{'using_if_exists' attribute only applies to named declarations, types, and value declarations}}
208 } // namespace test_appertains_to
210 typedef int *fake_FILE
;
214 using ::fake_FILE UIE
;
215 using ::fake_printf UIE
;
216 using ::fake_fopen UIE
; // expected-note {{using declaration annotated with 'using_if_exists' here}}
217 using ::fake_size_t UIE
; // expected-note {{using declaration annotated with 'using_if_exists' here}}
222 file
= std::fake_fopen(); // expected-error {{reference to unresolved using declaration}} expected-error{{incompatible integer to pointer}}
223 std::fake_size_t size
; // expected-error {{reference to unresolved using declaration}}
224 size
= fake_printf();
225 size
= std::fake_printf();