Skip to content

Commit 4afa9c5

Browse files
committed
Use tag name lookup for class names
This PR would fix #16855 . I think the correct lookup to use for class names is Tag name lookup, because it does not take namespaces into account. The current lookup does and because of this some valid programs are not accepted. If you think that Tag name lookup is not correct for all cases when we are looking up types based on class names then we can only do tag name lookup when looking up class names for inheritance. In case of inheritance: ``` [class.derived]p2 says: "During the lookup for a base class name, non-type names are ignored." ```
1 parent e290152 commit 4afa9c5

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,7 @@ Bug Fixes to C++ Support
516516
- Fixed a bug in lambda captures where ``constexpr`` class-type objects were not properly considered ODR-used in
517517
certain situations. (#GH47400), (#GH90896)
518518
- Fix erroneous templated array size calculation leading to crashes in generated code. (#GH41441)
519+
- During the lookup for a base class name, non-type names are ignored. (#GH16855)
519520

520521
Bug Fixes to AST Handling
521522
^^^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/Sema/SemaDecl.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -357,10 +357,13 @@ ParsedType Sema::getTypeName(const IdentifierInfo &II, SourceLocation NameLoc,
357357
return nullptr;
358358
}
359359

360-
// FIXME: LookupNestedNameSpecifierName isn't the right kind of
361-
// lookup for class-names.
362-
LookupNameKind Kind = isClassName ? LookupNestedNameSpecifierName :
363-
LookupOrdinaryName;
360+
// In the case where we know that the identifier is a class name, we know that
361+
// it is a type declaration (struct, class, union or enum) so we can use tag
362+
// name lookup.
363+
//
364+
// C++ [class.derived]p2 (wrt lookup in a base-specifier): The lookup for
365+
// the component name of the type-name or simple-template-id is type-only.
366+
LookupNameKind Kind = isClassName ? LookupTagName : LookupOrdinaryName;
364367
LookupResult Result(*this, &II, NameLoc, Kind);
365368
if (LookupCtx) {
366369
// Perform "qualified" name lookup into the declaration context we

clang/test/CXX/class.derived/p2.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,16 @@ namespace PR5840 {
66
struct Base {};
77
int Base = 10;
88
struct Derived : Base {};
9-
}
9+
} // namespace PR5840
10+
11+
namespace issue_16855 {
12+
struct x {};
13+
namespace
14+
{
15+
namespace x
16+
{
17+
struct y : x
18+
{};
19+
} // namespace x
20+
}
21+
} // namespace issue_16855

0 commit comments

Comments
 (0)