Files
TheRock/compiler/amd-llvm/clang/test/Sema/unqualified-lookup-local-class.cpp
T
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

78 lines
2.1 KiB
C++

// RUN: %clang_cc1 -std=c++20 -verify %s
// Regression test for PR184622: out-of-line definitions of nested classes
// inside a function must not be visible via unqualified lookup.
// Unqualified member access inside a class body is fine.
struct A1 {
int x;
void f() { x = 1; } // OK
};
struct Base {
int y;
};
struct Derived : Base {
void f() { y = 2; } // OK - inherited member
};
struct A2 { int z; };
struct B2 : A2 {
using A2::z;
void f() { z = 3; } // OK
};
// Out-of-line definitions at namespace scope are fine.
class OuterNS { public: class Inner; };
class OuterNS::Inner {}; // OK - not inside a function
// Out-of-line definitions of types nested in a class inside a function:
// the qualified form must work, but the unqualified name must not leak.
void pass1() {
struct A { struct B {}; };
A::B b; // OK - qualified
class C { public: class B; };
class C::B {};
C::B b2; // OK - qualified
}
template<class T>
struct Wrapper { Wrapper(T) {} };
// class nested in class, defined out-of-line inside function - unqualified 'B'
// must not be found.
void fail_class() {
class A { public: class B; };
class A::B {};
B b; // expected-error {{unknown type name 'B'}}
Wrapper w = Wrapper{B{}}; // expected-error {{use of undeclared identifier 'B'}}
A::B ok; // OK - qualified lookup still works
}
// Same rule applies to structs (TagDecl covers class/struct/union/enum).
void fail_struct() {
struct Outer { struct Inner; };
struct Outer::Inner {};
Inner bad; // expected-error {{unknown type name 'Inner'}}
Outer::Inner good; // OK
}
// Union nested in a class inside a function.
void fail_union() {
struct S { union U; };
union S::U { int a; float b; }; // expected-note {{'S::U' declared here}}
U bad; // expected-error {{unknown type name 'U'}}
S::U ok; // OK
}
// Multiple independent functions: each has its own scope, so 'B' in fail2
// is unrelated to 'B' in fail_class above.
void fail2() {
class Outer { public: class Inner; };
class Outer::Inner {};
Inner bad; // expected-error {{unknown type name 'Inner'}}
Outer::Inner good; // OK
}