xref: /llvm-project/clang/test/Misc/diag-inline-namespace.cpp (revision 48f73ee666a264d23716ff6bb671cad836b65ccf)
15f12f4ffSRichard Smith // RUN: %clang_cc1 -verify %s -std=c++20
25f12f4ffSRichard Smith 
35f12f4ffSRichard Smith // We avoid printing the name of an inline namespace unless it's necessary to
45f12f4ffSRichard Smith // uniquely identify the target.
55f12f4ffSRichard Smith namespace N {
65f12f4ffSRichard Smith   inline namespace A {
75f12f4ffSRichard Smith     inline namespace B {
85f12f4ffSRichard Smith       inline namespace C {
95f12f4ffSRichard Smith         int f, g, h, i, j;
105f12f4ffSRichard Smith         struct f; struct g; struct h; struct i; struct j;
115f12f4ffSRichard Smith       }
125f12f4ffSRichard Smith       struct g;
135f12f4ffSRichard Smith       struct j;
145f12f4ffSRichard Smith     }
155f12f4ffSRichard Smith     struct h;
165f12f4ffSRichard Smith   }
175f12f4ffSRichard Smith   struct i;
185f12f4ffSRichard Smith   struct j;
195f12f4ffSRichard Smith 
205f12f4ffSRichard Smith   template<int*> struct Q; // expected-note 5{{here}}
215f12f4ffSRichard Smith   Q<&A::B::C::f> q1; // expected-error {{implicit instantiation of undefined template 'N::Q<&N::f>'}}
225f12f4ffSRichard Smith   Q<&A::B::C::g> q2; // expected-error {{implicit instantiation of undefined template 'N::Q<&N::C::g>'}}
235f12f4ffSRichard Smith   Q<&A::B::C::h> q3; // expected-error {{implicit instantiation of undefined template 'N::Q<&N::B::h>'}}
245f12f4ffSRichard Smith   Q<&A::B::C::i> q4; // expected-error {{implicit instantiation of undefined template 'N::Q<&N::A::i>'}}
255f12f4ffSRichard Smith   Q<&A::B::C::j> q5; // expected-error {{implicit instantiation of undefined template 'N::Q<&N::C::j>'}}
265f12f4ffSRichard Smith 
275f12f4ffSRichard Smith   template<typename> struct R; // expected-note 5{{here}}
285f12f4ffSRichard Smith   R<struct A::B::C::f> r1; // expected-error {{implicit instantiation of undefined template 'N::R<N::f>'}}
295f12f4ffSRichard Smith   R<struct A::B::C::g> r2; // expected-error {{implicit instantiation of undefined template 'N::R<N::C::g>'}}
305f12f4ffSRichard Smith   R<struct A::B::C::h> r3; // expected-error {{implicit instantiation of undefined template 'N::R<N::B::h>'}}
315f12f4ffSRichard Smith   R<struct A::B::C::i> r4; // expected-error {{implicit instantiation of undefined template 'N::R<N::A::i>'}}
325f12f4ffSRichard Smith   R<struct A::B::C::j> r5; // expected-error {{implicit instantiation of undefined template 'N::R<N::C::j>'}}
335f12f4ffSRichard Smith 
345f12f4ffSRichard Smith   // Make the name N::C ambiguous.
355f12f4ffSRichard Smith   inline namespace A { int C; }
365f12f4ffSRichard Smith 
375f12f4ffSRichard Smith   template<int*> struct S; // expected-note 5{{here}}
385f12f4ffSRichard Smith   S<&A::B::C::f> s1; // expected-error {{implicit instantiation of undefined template 'N::S<&N::f>'}}
395f12f4ffSRichard Smith   S<&A::B::C::g> s2; // expected-error {{implicit instantiation of undefined template 'N::S<&N::B::C::g>'}}
405f12f4ffSRichard Smith   S<&A::B::C::h> s3; // expected-error {{implicit instantiation of undefined template 'N::S<&N::B::h>'}}
415f12f4ffSRichard Smith   S<&A::B::C::i> s4; // expected-error {{implicit instantiation of undefined template 'N::S<&N::A::i>'}}
425f12f4ffSRichard Smith   S<&A::B::C::j> s5; // expected-error {{implicit instantiation of undefined template 'N::S<&N::B::C::j>'}}
435f12f4ffSRichard Smith 
445f12f4ffSRichard Smith   template<typename> struct T; // expected-note 5{{here}}
455f12f4ffSRichard Smith   T<struct A::B::C::f> t1; // expected-error {{implicit instantiation of undefined template 'N::T<N::f>'}}
465f12f4ffSRichard Smith   T<struct A::B::C::g> t2; // expected-error {{implicit instantiation of undefined template 'N::T<N::B::C::g>'}}
475f12f4ffSRichard Smith   T<struct A::B::C::h> t3; // expected-error {{implicit instantiation of undefined template 'N::T<N::B::h>'}}
485f12f4ffSRichard Smith   T<struct A::B::C::i> t4; // expected-error {{implicit instantiation of undefined template 'N::T<N::A::i>'}}
495f12f4ffSRichard Smith   T<struct A::B::C::j> t5; // expected-error {{implicit instantiation of undefined template 'N::T<N::B::C::j>'}}
505f12f4ffSRichard Smith }
51*48f73ee6SAaron Ballman 
52*48f73ee6SAaron Ballman namespace dont_crash {
53*48f73ee6SAaron Ballman // A malformed lookup involving inline namespaces in a linkage specification
54*48f73ee6SAaron Ballman // would previous cause an assertion due to the way diagnostics are emitted.
55*48f73ee6SAaron Ballman extern "C++" inline namespace {
56*48f73ee6SAaron Ballman namespace a {
57*48f73ee6SAaron Ballman   a : b // expected-error {{unexpected ':' in nested name specifier; did you mean '::'?}} \
58*48f73ee6SAaron Ballman         // expected-error {{no type named 'b' in namespace 'dont_crash::a'}}
59*48f73ee6SAaron Ballman } // expected-error {{expected unqualified-id}}
60*48f73ee6SAaron Ballman } // inline namespace
61*48f73ee6SAaron Ballman } // dont_crash
62